-
Notifications
You must be signed in to change notification settings - Fork 382
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(engine-server): faster
<style>
validation (#4201)
Co-authored-by: Will Harney <62956339+wjhsf@users.noreply.github.com>
- Loading branch information
1 parent
af03411
commit 5bb6f12
Showing
3 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
packages/@lwc/engine-server/src/__tests__/validate-style-text-contents.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,40 @@ | ||
/* | ||
* Copyright (c) 2024, Salesforce, Inc. | ||
* All rights reserved. | ||
* SPDX-License-Identifier: MIT | ||
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT | ||
*/ | ||
import { validateStyleTextContents } from '../utils/validate-style-text-contents'; | ||
|
||
// See https://html.spec.whatwg.org/multipage/syntax.html#cdata-rcdata-restrictions | ||
describe('validateStyleTextContents', () => { | ||
it('throws an error for invalid style text content', () => { | ||
const invalidStrings = [ | ||
'</style\t', | ||
'</style\n', | ||
'</style\f', | ||
'</style\r', | ||
'</style ', | ||
'</style>', | ||
'</style/', | ||
]; | ||
|
||
for (const invalidString of invalidStrings) { | ||
expect(() => validateStyleTextContents(invalidString)).toThrow( | ||
/CSS contains unsafe characters/ | ||
); | ||
expect(() => validateStyleTextContents(invalidString.toUpperCase())).toThrow( | ||
/CSS contains unsafe characters/ | ||
); | ||
} | ||
}); | ||
|
||
it('does not throw for valid text content', () => { | ||
const validStrings = ['</style', '</ style>', `data-foo="<>'&"] {}`, `data-foo='"'] {}`]; | ||
|
||
for (const validString of validStrings) { | ||
expect(() => validateStyleTextContents(validString)).not.toThrow(); | ||
expect(() => validateStyleTextContents(validString.toUpperCase())).not.toThrow(); | ||
} | ||
}); | ||
}); |
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