diff options
| author | Henry Jameson <me@hjkos.com> | 2021-06-07 16:31:39 +0300 |
|---|---|---|
| committer | Henry Jameson <me@hjkos.com> | 2021-06-07 18:41:47 +0300 |
| commit | b0ae32e309134f0e91026c6712f2e9081f493c22 (patch) | |
| tree | 6762192fd592539c4f92e1190f2c98b070f3d79f | |
| parent | 22c8f71945c6d114bf4db89c87eb1b166775f2d6 (diff) | |
made getAttrs correctly handle both ' and "
| -rw-r--r-- | src/services/mini_html_converter/mini_html_converter.service.js | 4 | ||||
| -rw-r--r-- | test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/src/services/mini_html_converter/mini_html_converter.service.js b/src/services/mini_html_converter/mini_html_converter.service.js index 879ff544..01f8adf8 100644 --- a/src/services/mini_html_converter/mini_html_converter.service.js +++ b/src/services/mini_html_converter/mini_html_converter.service.js @@ -128,11 +128,11 @@ export const getAttrs = tag => { .replace(new RegExp('^' + getTagName(tag)), '') .replace(/\/?$/, '') .trim() - const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=(?:"([^"]+?)"|'([^']+?)'))?/gi)) + const attrs = Array.from(innertag.matchAll(/([a-z0-9-]+)(?:=("[^"]+?"|'[^']+?'))?/gi)) .map(([trash, key, value]) => [key, value]) .map(([k, v]) => { if (!v) return [k, true] - return [k, v] + return [k, v.substring(1, v.length - 1)] }) return Object.fromEntries(attrs) } diff --git a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js index b42f5f35..8df2fbc3 100644 --- a/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js +++ b/test/unit/specs/services/tiny_post_html_processor/mini_post_html_processor.spec.js @@ -157,7 +157,7 @@ describe('MiniHtmlConverter', () => { describe('getAttrs', () => { it('extracts arguments from tag', () => { - const input = '<img src="boop" cool ebin="true">' + const input = '<img src="boop" cool ebin=\'true\'>' const output = { src: 'boop', cool: true, ebin: 'true' } expect(getAttrs(input)).to.eql(output) |
