diff --git a/CHANGES.rst b/CHANGES.rst index 87b70577..9997aad4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -15,8 +15,6 @@ New Features .. _#966: https://github.com/posativ/isso/pull/966 .. _#998: https://github.com/isso-comments/isso/pull/998 .. _#1000: https://github.com/isso-comments/isso/pull/1000 -.. _#966: https://github.com/posativ/isso/pull/966 -.. _#998: https://github.com/isso-comments/isso/pull/998 .. _#1001: https://github.com/isso-comments/isso/pull/1001 Breaking Changes @@ -34,6 +32,7 @@ Bugfixes & Improvements - Fix W3C Validation issues (`#999`_, pkvach) - Handle deleted comments in Disqus migration (`#994`_, pkvach) - Fix total comments count calculation (`#997`_, pkvach) +- Fix newline character handling in data-isso-* i18n strings (`#992`_, pkvach) .. _#951: https://github.com/posativ/isso/pull/951 .. _#967: https://github.com/posativ/isso/pull/967 @@ -42,6 +41,7 @@ Bugfixes & Improvements .. _#999: https://github.com/isso-comments/isso/pull/999 .. _#994: https://github.com/isso-comments/isso/pull/994 .. _#997: https://github.com/isso-comments/isso/pull/997 +.. _#992: https://github.com/isso-comments/isso/pull/992 0.13.1.dev0 (2023-02-05) ------------------------ diff --git a/isso/js/app/config.js b/isso/js/app/config.js index 71d5f569..4ce92fbb 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -16,22 +16,25 @@ for (var i = 0; i < js.length; i++) { for (var j = 0; j < js[i].attributes.length; j++) { var attr = js[i].attributes[j]; if (/^data-isso-/.test(attr.name)) { - try { - // Normalize underscores to dashes so that language-specific - // strings can be caught better later on, - // e.g. data-isso-postbox-text-text-PT_BR becomes - // postbox-text-text-pt-br. - // Also note that attr.name only gives lowercase strings as per - // HTML spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since - // the test environment's jest-environment-jsdom seemingly does - // not follow that convention, convert to lowercase here anyway. - config[attr.name.substring(10) + + // Normalize underscores to dashes so that language-specific + // strings can be caught better later on, e.g. + // data-isso-postbox-text-text-PT_BR becomes postbox-text-text-pt-br. + // Also note that attr.name only gives lowercase strings as per HTML + // spec, e.g. data-isso-FOO-Bar becomes foo-bar, but since the test + // environment's jest-environment-jsdom seemingly does not follow + // that convention, convert to lowercase here anyway. + const attrName = attr.name.substring(10) .replace(/_/g, '-') - .toLowerCase()] = JSON.parse(attr.value); + .toLowerCase() + + // Replace escaped newline characters in the attribute value with actual newline characters + const attrValue = attr.value.replace(/\\n/g, '\n'); + + try { + config[attrName] = JSON.parse(attrValue); } catch (ex) { - config[attr.name.substring(10) - .replace(/_/g, '-') - .toLowerCase()] = attr.value; + config[attrName] = attrValue; } } } diff --git a/isso/js/tests/unit/config.test.js b/isso/js/tests/unit/config.test.js index 43f2beb3..08724985 100644 --- a/isso/js/tests/unit/config.test.js +++ b/isso/js/tests/unit/config.test.js @@ -9,6 +9,11 @@ "use strict"; +beforeEach(() => { + jest.resetModules(); + document.body.innerHTML = ''; +}); + test("Client configuration - no languages", () => { // Mock navigator.languages = [] global.languages = jest.spyOn(navigator, "languages", "get") @@ -35,3 +40,21 @@ test("Client configuration - no languages", () => { expect(config["langs"]).toStrictEqual(expected_langs); }); + +test("data-isso-* i18n strings should be accepted with newline characters", () => { + + document.body.innerHTML = + '
' + + // Note: `src` and `data-isso` need to be set, + // else `api` fails to initialize! + '