From 19ffe0cbafe7793e915c44395bd98e1b70305b35 Mon Sep 17 00:00:00 2001 From: Cosmin Popovici Date: Sat, 1 Oct 2022 16:07:32 +0300 Subject: [PATCH] fix: don't require _options for urlParameters transformer --- src/transformers/urlParameters.js | 8 ++++---- test/test-transformers.js | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/transformers/urlParameters.js b/src/transformers/urlParameters.js index 098d967d..b57bf847 100644 --- a/src/transformers/urlParameters.js +++ b/src/transformers/urlParameters.js @@ -6,11 +6,11 @@ module.exports = async (html, config = {}, direct = false) => { const urlParameters = direct ? config : get(config, 'urlParameters', {}) if (!isEmpty(urlParameters)) { - const {_options, ...parameters} = urlParameters - const tags = _options.tags ?? ['a'] - const strict = _options.strict ?? true - const qs = _options.qs ?? {encode: false} const posthtmlOptions = get(config, 'build.posthtml.options', {}) + const {_options, ...parameters} = urlParameters + const tags = get(_options, 'tags', ['a']) + const strict = get(_options, 'strict', true) + const qs = get(_options, 'qs', {encode: false}) return posthtml([urlParams({parameters, tags, qs, strict})]).process(html, posthtmlOptions).then(result => result.html) } diff --git a/test/test-transformers.js b/test/test-transformers.js index 15194830..00e719a1 100644 --- a/test/test-transformers.js +++ b/test/test-transformers.js @@ -315,20 +315,35 @@ test('filters (postcss)', async t => { }) test('url parameters', async t => { - const html = await Maizzle.addURLParams( + const simple = await Maizzle.addURLParams( + `test + `, + { + bar: 'baz', + qix: 'qux' + } + ) + + const withOptions = await Maizzle.addURLParams( `test `, { _options: { tags: ['a[href*="example"]'], - strict: false + strict: false, + qs: { + encode: true + } }, - bar: 'baz', - qix: 'qux' + foo: '@Bar@', + bar: 'baz' } ) - t.is(html, `test + t.is(simple, `test + `) + + t.is(withOptions, `test `) })