From 2e83211388a1e5ad2ae9ffb4080be1af12d8ca76 Mon Sep 17 00:00:00 2001 From: Justin Sprigg Date: Sun, 21 Jan 2018 00:28:56 +1100 Subject: [PATCH] Quoted attributes regex fix (#17) * Fixed newline characters inside of quoted attributes * Added test * Swapped to negation selector --- index.js | 2 +- tests/test.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 859324c3..586fca13 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ module.exports = parse; var re_name = /^(?:\\.|[\w\-\u00c0-\uFFFF])+/, re_escape = /\\([\da-f]{1,6}\s?|(\s)|.)/ig, //modified version of https://github.com/jquery/sizzle/blob/master/src/sizzle.js#L87 - re_attr = /^\s*((?:\\.|[\w\u00c0-\uFFFF\-])+)\s*(?:(\S?)=\s*(?:(['"])(.*?)\3|(#?(?:\\.|[\w\u00c0-\uFFFF\-])*)|)|)\s*(i)?\]/; + re_attr = /^\s*((?:\\.|[\w\u00c0-\uFFFF\-])+)\s*(?:(\S?)=\s*(?:(['"])([^]*?)\3|(#?(?:\\.|[\w\u00c0-\uFFFF\-])*)|)|)\s*(i)?\]/; var actionTypes = { __proto__: null, diff --git a/tests/test.js b/tests/test.js index 30a9f656..ddc03d6f 100644 --- a/tests/test.js +++ b/tests/test.js @@ -250,6 +250,21 @@ var tests = [ ], "quoted attribute with spaces" ], + [ + "[value=\"\nsome text\n\"]", + [ + [ + { + "type": "attribute", + "name": "value", + "action": "equals", + "value": "\nsome text\n", + "ignoreCase": false + } + ] + ], + "quoted attribute with internal newline" + ], [ "[name=foo\\.baz]", [