From 9f9480c0499b1f84752fb4a10e68709e8825ee75 Mon Sep 17 00:00:00 2001 From: vi Date: Fri, 25 Jul 2014 13:47:57 +0800 Subject: [PATCH] (Forgivingly) permit ["/.] in attribute names. --- src/Text/Taggy/Parser.hs | 16 ++-------------- tests/Text/Taggy/ParserSpec.hs | 7 +++++++ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Text/Taggy/Parser.hs b/src/Text/Taggy/Parser.hs index 485e022..5709e6b 100644 --- a/src/Text/Taggy/Parser.hs +++ b/src/Text/Taggy/Parser.hs @@ -84,23 +84,11 @@ possibly c = (char c *> return ()) ident :: Parser T.Text ident = - takeWhile1 (\c -> isAlphaNum c - || c == '-' - || c == '_' - || c == ':' - || c == '.' - ) + takeWhile1 (\c -> isAlphaNum c || c `elem` "-_:.") attribute_ident :: Parser T.Text attribute_ident = - takeWhile1 (\c -> isAlphaNum c - || c == '-' - || c == '_' - || c == ':' - || c == '(' - || c == ')' - || c == ',' - ) + takeWhile1 (\c -> isAlphaNum c || c `elem` "-_:(),\"/.") tagopen :: Bool -> Parser Tag tagopen cventities = do diff --git a/tests/Text/Taggy/ParserSpec.hs b/tests/Text/Taggy/ParserSpec.hs index 3fbc25e..5679a7f 100644 --- a/tests/Text/Taggy/ParserSpec.hs +++ b/tests/Text/Taggy/ParserSpec.hs @@ -45,6 +45,13 @@ spec = do "
" ~> tagopen False `shouldParse` TagOpen "br" [] True + it "successfully (and forgivingly) parses " $ + "<title foo\">" ~> tagopen False + `shouldParse` TagOpen "title" [Attribute "foo\"" ""] False + it "successfully (and forgivingly) parses <title https://github.com/alpmestan/taggy\">" $ + "<title https://github.com/alpmestan/taggy/\">" ~> tagopen False + `shouldParse` TagOpen "title" [Attribute "https://github.com/alpmestan/taggy/\"" ""] False + it "can successfully convert entities in attribute values: <a title=\" Hello!\">" $ "<a title=\" Hello!\">" ~> tagopen True `shouldParse` TagOpen "a" [Attribute "title" "\160Hello!"] False