From 40bc7cd846ca22770173ec3a04d942c42ecb53db Mon Sep 17 00:00:00 2001 From: Ludovico Fischer Date: Thu, 6 May 2021 22:49:30 +0200 Subject: [PATCH] fix: parse quoted attributes containing a new line correctly Also match new lines in the regex that checks for quoted attributes. --- src/__tests__/attributes.js | 7 +++++++ src/selectors/attribute.js | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/__tests__/attributes.js b/src/__tests__/attributes.js index 2e46968..9239b56 100644 --- a/src/__tests__/attributes.js +++ b/src/__tests__/attributes.js @@ -367,6 +367,13 @@ test('extraneous non-combinating whitespace', ' [href] , [class] ', (t, tr t.deepEqual(tree.nodes[1].nodes[0].spaces.after, ' '); }); +test('newline in attribute selector', '[class="woop \\\nwoop woop"]', (t, tree) => { + t.deepEqual(tree.nodes[0].nodes[0].attribute, 'class'); + t.deepEqual(tree.nodes[0].nodes[0].operator, '='); + t.deepEqual(tree.nodes[0].nodes[0].value, 'woop \nwoop woop'); + t.true(tree.nodes[0].nodes[0].quoted); +}); + test('comments within attribute selectors', '[href/* wow */=/* wow */test]', (t, tree) => { t.deepEqual(tree.nodes[0].nodes[0].attribute, 'href'); t.deepEqual(tree.nodes[0].nodes[0].operator, '='); diff --git a/src/selectors/attribute.js b/src/selectors/attribute.js index eebe80f..723863a 100644 --- a/src/selectors/attribute.js +++ b/src/selectors/attribute.js @@ -5,7 +5,7 @@ import {ATTRIBUTE} from './types'; const deprecate = require("util-deprecate"); -const WRAPPED_IN_QUOTES = /^('|")(.*)\1$/; +const WRAPPED_IN_QUOTES = /^('|")([^]*)\1$/; const warnOfDeprecatedValueAssignment = deprecate(() => {}, "Assigning an attribute a value containing characters that might need to be escaped is deprecated. " +