diff --git a/HISTORY.md b/HISTORY.md index 8c9d1e264..b83799e3f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,11 @@ https://github.com/josdejong/jsoneditor +## not yet published, version 9.5.6 + +- Fix inefficient regex to replace return characters. + + ## 2021-09-01, version 9.5.5 - Fix `setMode` not throwing an exception anymore in case of a parse error diff --git a/src/js/util.js b/src/js/util.js index 9316e5fd0..997785543 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -399,8 +399,8 @@ export function getInnerText (element, buffer) { // text node if (element.nodeValue) { - // remove return characters and the whitespace surrounding return characters - const trimmedValue = element.nodeValue.replace(/\s*\n\s*/g, '') + // remove return characters and the whitespaces surrounding those return characters + const trimmedValue = element.nodeValue.replace(/(\b|^)\s*\n\s*(\b|$)/g, '') if (trimmedValue !== '') { return buffer.flush() + trimmedValue } else {