Skip to content

Commit

Permalink
Fix inefficient regex to replace return characters
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Sep 22, 2021
1 parent c33544b commit 092e386
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/js/util.js
Expand Up @@ -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 {
Expand Down

0 comments on commit 092e386

Please sign in to comment.