From 0e1cef758bc9d04554edbaf8074ce539ffc9f9d7 Mon Sep 17 00:00:00 2001 From: Bryan Butler Date: Thu, 27 May 2021 17:27:21 -0500 Subject: [PATCH] Escape double quotes on attribute values and add tests. --- src/index.js | 2 +- test/to-string.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 3197dc8..79a61ed 100644 --- a/src/index.js +++ b/src/index.js @@ -89,7 +89,7 @@ class DrupalAttribute extends Map { value = value.join(' '); } - components.push([key, '"' + value + '"'].join('=')); + components.push([key, '"' + value.replace(/"/g, '"') + '"'].join('=')); }); let rendered = components.join(' '); diff --git a/test/to-string.js b/test/to-string.js index b117058..5302f32 100644 --- a/test/to-string.js +++ b/test/to-string.js @@ -18,9 +18,10 @@ tap.test('toString', function(test) { .setAttribute('foo', 'bar') .setAttribute('bar', 'foo') .setAttribute('foo-bar', ['foo', 'bar']) + .setAttribute('foobar', '"foo bar"' ) ; - test.equal(attribute.toString(), ' foo="bar" bar="foo" foo-bar="foo bar"'); + test.equal(attribute.toString(), ' foo="bar" bar="foo" foo-bar="foo bar" foobar=""foo bar""'); test.end(); }); });