Skip to content

Commit 092e386

Browse files
committed
Fix inefficient regex to replace return characters
1 parent c33544b commit 092e386

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
https://github.com/josdejong/jsoneditor
44

55

6+
## not yet published, version 9.5.6
7+
8+
- Fix inefficient regex to replace return characters.
9+
10+
611
## 2021-09-01, version 9.5.5
712

813
- Fix `setMode` not throwing an exception anymore in case of a parse error

src/js/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ export function getInnerText (element, buffer) {
399399

400400
// text node
401401
if (element.nodeValue) {
402-
// remove return characters and the whitespace surrounding return characters
403-
const trimmedValue = element.nodeValue.replace(/\s*\n\s*/g, '')
402+
// remove return characters and the whitespaces surrounding those return characters
403+
const trimmedValue = element.nodeValue.replace(/(\b|^)\s*\n\s*(\b|$)/g, '')
404404
if (trimmedValue !== '') {
405405
return buffer.flush() + trimmedValue
406406
} else {

0 commit comments

Comments
 (0)