-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(designer-ui): Prevent expressions using
&...;
syntax disappeari…
…ng from HTML editor (#3760) * Make into a promise * Encode token expression values * Move encoders to helper file * Remove unused encoder * Move encoding to 'convertEditorState' * Revert unneeded change * Fix appending of encoded nodes * Remove unused method * Add one more test case * Convert insecure regex to a helper * Fix handling of `"` * Fix neglected test case
- Loading branch information
1 parent
b75f328
commit b7b7aaa
Showing
6 changed files
with
133 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
libs/designer-ui/src/lib/editor/base/utils/__test__/parsesegments.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { encodeStringSegments } from '../parsesegments'; | ||
|
||
describe('lib/editor/base/utils/parseSegments', () => { | ||
describe('encodeStringSegments', () => { | ||
it.each([ | ||
['plain text', 'plain text'], | ||
[`$[concat(...),concat('<'),#AD008C]$`, `$[concat(...),concat('%26lt;'),#AD008C]$`], | ||
[`text$[concat(...),concat('<'),#AD008C]$text`, `text$[concat(...),concat('%26lt;'),#AD008C]$text`], | ||
[ | ||
`$[replace(...),replace(replace(replace('abc','<','<'),'>','>'),'"','"') ,#AD008C]$`, | ||
`$[replace(...),replace(replace(replace('abc','%26lt;','<'),'%26gt;','>'),'%26quot;','%22') ,#AD008C]$`, | ||
], | ||
])('should properly encode segments in: %p', (input, expected) => { | ||
expect(encodeStringSegments(input, true)).toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 41 additions & 10 deletions
51
libs/designer-ui/src/lib/html/plugins/toolbar/helper/__test__/util.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,50 @@ | ||
import { cleanHtmlString } from "../util"; | ||
import { cleanHtmlString, decodeSegmentValue, encodeSegmentValue } from '../util'; | ||
|
||
describe('lib/html/plugins/toolbar/helper/util', () => { | ||
describe('cleanHtmlString', () => { | ||
it.each([ | ||
["<p>text1<span>\n</span>text2</p>", "<p>text1<br>text2</p>"], | ||
["<p>text</p>", "<p>text</p>"], | ||
["<p>text1</p><p><br></p><p>text2</p>", "<p>text1</p><br><p>text2</p>"], | ||
["<p>text1<br></p><p><br></p><p>text2</p>", "<p>text1</p><br><br><p>text2</p>"], | ||
["<span>text</span>", "text"], | ||
[ | ||
"<span id=\"$[abc,variables('abc'),#770bd6]$\">text</span>", | ||
"<span id=\"$[abc,variables('abc'),#770bd6]$\">text</span>", | ||
], | ||
['<p>text1<span>\n</span>text2</p>', '<p>text1<br>text2</p>'], | ||
['<p>text</p>', '<p>text</p>'], | ||
['<p>text1</p><p><br></p><p>text2</p>', '<p>text1</p><br><p>text2</p>'], | ||
['<p>text1<br></p><p><br></p><p>text2</p>', '<p>text1</p><br><br><p>text2</p>'], | ||
['<span>text</span>', 'text'], | ||
['<span id="$[abc,variables(\'abc\'),#770bd6]$">text</span>', '<span id="$[abc,variables(\'abc\'),#770bd6]$">text</span>'], | ||
['<span id="$[concat(\'<\'),#ad008c]$">text</span>', '<span id="$[concat(\'<\'),#ad008c]$">text</span>'], | ||
['<span id="$[concat(\'%26lt;\'),#ad008c]$">text</span>', '<span id="$[concat(\'%26lt;\'),#ad008c]$">text</span>'], | ||
])('should properly convert HTML: %p', (input, expected) => { | ||
expect(cleanHtmlString(input)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('decodeSegmentValue', () => { | ||
it.each([ | ||
['plain text', 'plain text'], | ||
['text with %26lt;%26gt;', 'text with <>'], | ||
['text with %26noIdeaWhatThisIs;', 'text with &noIdeaWhatThisIs;'], | ||
['text with %26#60;%26gt;', 'text with <>'], | ||
['text with %26amp;lt;%26amp;gt;', 'text with &lt;&gt;'], | ||
['text with %22%26quot;%22', 'text with """'], | ||
["$[concat(...),concat('abc'),#AD008C]$", "$[concat(...),concat('abc'),#AD008C]$"], | ||
["$[concat(...),concat('%26lt;'),#AD008C]$", "$[concat(...),concat('<'),#AD008C]$"], | ||
["$[concat(...),concat('%26amp;lt;'),#AD008C]$", "$[concat(...),concat('&lt;'),#AD008C]$"], | ||
])('should properly decode segments in: %p', (input, expected) => { | ||
expect(decodeSegmentValue(input)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('encodeSegmentValue', () => { | ||
it.each([ | ||
['plain text', 'plain text'], | ||
['text with <>', 'text with %26lt;%26gt;'], | ||
['text with &noIdeaWhatThisIs;', 'text with %26noIdeaWhatThisIs;'], | ||
['text with <>', 'text with %26#60;%26gt;'], | ||
['text with &lt;&gt;', 'text with %26amp;lt;%26amp;gt;'], | ||
['text with """', 'text with %22%26quot;%22'], | ||
["$[concat(...),concat('abc'),#AD008C]$", "$[concat(...),concat('abc'),#AD008C]$"], | ||
["$[concat(...),concat('<'),#AD008C]$", "$[concat(...),concat('%26lt;'),#AD008C]$"], | ||
["$[concat(...),concat('&lt;'),#AD008C]$", "$[concat(...),concat('%26amp;lt;'),#AD008C]$"], | ||
])('should properly encode segments in: %p', (input, expected) => { | ||
expect(encodeSegmentValue(input)).toBe(expected); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters