-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix: inject HTML before <script> if top-level #32982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alexsch01
wants to merge
8
commits into
cypress-io:develop
Choose a base branch
from
alexsch01:inject-top-script
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+76
−4
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
62ecdd2
fix: inject HTML before <script> if top-level
alexsch01 a405085
use htmlMatch over headMatch
alexsch01 78d7044
Update CHANGELOG.md
alexsch01 2872c16
Create rewriter.spec.ts
alexsch01 304fece
hopefully fix lint
alexsch01 536ef85
Fix mocked
alexsch01 be98238
fix lint
alexsch01 51eee94
empty run semantic PR test
alexsch01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,43 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { html } from '../../../../lib/http/util/rewriter' | ||
|
|
||
| const injected = `<script>(() => { TEST })()</script>` | ||
|
|
||
| describe('http/util/rewriter', () => { | ||
| describe('.top-level tests', () => { | ||
| it('just a script tag', async () => { | ||
| expect(await html('<script>Original HTML</script>', {} as any, injected)) | ||
| .toEqual(`${injected} <script>Original HTML</script>`) | ||
| }) | ||
|
|
||
| it('script tag before a html tag', async () => { | ||
| expect(await html('<script>Original Script</script><html>Test HTML</html>', {} as any, injected)) | ||
| .toEqual(`${injected} <script>Original Script</script><html>Test HTML</html>`) | ||
| }) | ||
|
|
||
| it('script tag after a html tag', async () => { | ||
| expect(await html('<html>Test HTML</html><script>Original Script</script>', {} as any, injected)) | ||
| .toEqual(`<html> <head> ${injected} </head>Test HTML</html><script>Original Script</script>`) | ||
| }) | ||
|
|
||
| it('script tag inside head tag with no body tag', async () => { | ||
| expect(await html('<html><head><script>Original Script</script></head></html>', {} as any, injected)) | ||
| .toEqual(`<html><head> ${injected}<script>Original Script</script></head></html>`) | ||
| }) | ||
|
|
||
| it('script tag inside head tag with a body tag', async () => { | ||
| expect(await html('<html><head><script>Original Script</script></head><body>Example Body</body></html>', {} as any, injected)) | ||
| .toEqual(`<html><head> ${injected}<script>Original Script</script></head><body>Example Body</body></html>`) | ||
| }) | ||
|
|
||
| it('script tag inside body tag with no head tag', async () => { | ||
| expect(await html('<html><body><script>Original Script</script></body></html>', {} as any, injected)) | ||
| .toEqual(`<html><head> ${injected} </head> <body><script>Original Script</script></body></html>`) | ||
| }) | ||
|
|
||
| it('script tag inside body tag with a head tag', async () => { | ||
| expect(await html('<html><head>Original Head</head><body><script>Original Script</script></body></html>', {} as any, injected)) | ||
| .toEqual(`<html><head> ${injected}Original Head</head><body><script>Original Script</script></body></html>`) | ||
| }) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.