Skip to content

Add test to verify that document.currentScript.src should not get clobbered by a DOM element with name='currentScript'. #48536

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juj
Copy link
Contributor

@juj juj commented Oct 9, 2024

Add test to verify that document.currentScript.src should not get clobbered by a DOM element with name='currentScript'. See whatwg/html#10687 for details.

This is still pending browser vendor discussion, adding a test early to illustrate what it would look like.

…bbered by a DOM element with name='currentScript'. See whatwg/html#10687 for details.
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to add an assert_equals whereby you compare the actual node in question. That would obviate most of the other asserts (though we could keep them for debugging purposes).

<script>
test(function() {
assert_true(document.currentScript.tagName === 'SCRIPT'); // In particular, should not be "IMG" from the DOM element
assert_true(!document.currentScript.src.includes('malevolent_address')); // Should not have gotten the URL address from IMG element
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use assert_false.

test(function() {
assert_true(document.currentScript.tagName === 'SCRIPT'); // In particular, should not be "IMG" from the DOM element
assert_true(!document.currentScript.src.includes('malevolent_address')); // Should not have gotten the URL address from IMG element
assert_true(document.currentScript.src == ''); // In fact, since this is an inline <script> element, .src should be empty.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_equals would give a clearer error message here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants