Skip to content

Conversation

@patel-vansh
Copy link
Owner

This pull request adds a comprehensive set of new test fixtures for Svelte files, focusing on scenarios involving unsafe raw HTML insertion, comment handling, control flow blocks, and malformed HTML. The changes improve coverage for edge cases in HTML sanitization warnings and the handling of ignore comments in Svelte templates.

Test coverage for unsafe HTML insertion and ignore comments

  • Added fixtures for complex expressions using {@html ...} with and without ignore comments, ensuring warnings are correctly emitted or suppressed. (ComplexExpression.svelte, ComplexExpression.expected.json, ComplexExpressionWithComment.svelte, `ComplexExpressionWithComment.expected.j
    This pull request adds several new Svelte test fixtures and their expected JSON outputs to improve coverage of unsafe raw HTML insertion detection and comment-based ignore logic. The changes focus on verifying that warnings are correctly generated for unsafe HTML insertions, and that the presence of ignore comments suppresses these warnings as intended. Additionally, tests are included for edge cases such as empty files, comments, malformed HTML, and expressions inside control flow blocks.

Unsafe HTML detection and ignore comment handling:

  • Added tests (ComplexExpression.svelte, ComplexExpressionWithComment.svelte, InsideEach.svelte, InsideEachWithComment.svelte, InsideIf.svelte, InsideIfWithComment.svelte) to verify that warnings are raised for unsafe raw HTML insertions, and that these warnings are suppressed when the svelte-ignore unsafe_html comment is present.

Edge case and miscellaneous test coverage:

  • Added fixtures for empty files and files containing only comments to confirm that no warnings are generated in these scenarios (Empty.svelte, EmptyWithComment.svelte, EmptyWithComment.svelte, OneUnsafeWithIgnoreComment.expected.json renamed).
  • Added tests for code and HTML comments containing unsafe HTML expressions to ensure they do not trigger false positives (InComments.svelte, InComments.expected.json).
  • Added a test for malformed HTML to verify parser robustness and that no warnings are raised for structural issues alone (MalformedHTML.svelte, MalformedHTML.expected.json).
  • Added fixtures for unsafe HTML inside {#each} and {#if} blocks, including versions with ignore comments to verify warning suppression. (InsideEach.svelte, InsideEach.expected.json, InsideEachWithComment.svelte, InsideEachWithComment.expected.json, InsideIf.svelte, InsideIf.expected.json, InsideIfWithComment.svelte, InsideIfWithComment.expected.json)

Edge case handling and miscellaneous scenarios

  • Added fixtures for files containing only comments, empty files, and files with commented-out {@html ...} usages to confirm no false positives in warning generation. (EmptyWithComment.svelte, EmptyWithComment.expected.json, InComments.svelte, InComments.expected.json, Empty.svelte, Empty.expected.json)

File renaming for clarity

  • Renamed OneUnsafeWithIgnoreComment.expected.json to OneUnsafeWithComment.expected.json to better reflect the fixture's content.

These additions ensure the test suite robustly covers various Svelte template scenarios, improving reliability and accuracy of HTML sanitization checks.

@patel-vansh patel-vansh self-assigned this Nov 11, 2025
@patel-vansh patel-vansh added the enhancement New feature or request label Nov 11, 2025
@patel-vansh patel-vansh merged commit adcf2fa into main Nov 11, 2025
3 checks passed
@patel-vansh patel-vansh deleted the test/add-new-tests branch November 11, 2025 10:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant