diff --git a/CHANGES.rst b/CHANGES.rst index 718368a9..d82d808b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,6 +27,7 @@ Bugfixes & Improvements - Prevent auto creation of invalid links in comments (`#995`_, pkvach) - Fix W3C Validation issues (`#999`_, pkvach) - Handle deleted comments in Disqus migration (`#994`_, 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 @@ -34,6 +35,7 @@ Bugfixes & Improvements .. _#995: https://github.com/isso-comments/isso/pull/995 .. _#999: https://github.com/isso-comments/isso/pull/999 .. _#994: https://github.com/isso-comments/isso/pull/994 +.. _#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..8684e8dc 100644 --- a/isso/js/app/config.js +++ b/isso/js/app/config.js @@ -16,6 +16,10 @@ 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)) { + + // Replace escaped newline characters in the attribute value with actual newline characters + const attrValue = attr.value.replace(/\\n/g, '\n'); + try { // Normalize underscores to dashes so that language-specific // strings can be caught better later on, @@ -27,11 +31,11 @@ for (var i = 0; i < js.length; i++) { // not follow that convention, convert to lowercase here anyway. config[attr.name.substring(10) .replace(/_/g, '-') - .toLowerCase()] = JSON.parse(attr.value); + .toLowerCase()] = JSON.parse(attrValue); } catch (ex) { config[attr.name.substring(10) .replace(/_/g, '-') - .toLowerCase()] = attr.value; + .toLowerCase()] = 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! + '