Skip to content
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

snippet_viewer.ts DOM text reinterpreted as HTML #4747

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ ${css_beautify(this.renderedStyle)}
get formattedHtml() {
// Removes LitElement render artifacts e.g. <!--?lit$515089429$-->
// the `?` in `.*?` is a non-greedy match.
let html = this.shadowTag.innerHTML.replace(/<!--.*?-->/g, '');
let html = this.shadowTag.innerText.replace(/<!--.*?-->/g, '');
// Removes empty lines that may result from the previous line
html = html.replace(/\n\s*\n/g, '');
// Remove the ar-status runtime-added tag
Expand Down
54 changes: 23 additions & 31 deletions packages/space-opera/src/test/snippet_viewer/snippet_viewer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,17 @@ suite('snippet viewer test', () => {
});

test('formatted HTML strips Lit comments', async () => {
// clang-format off

// Pulled from real DOM of astronaut example.
snippetViewer.renderedSnippet = html`<!--?lit$343342268$--><model-viewer src="Astronaut.glb" ar="" camera-controls="" poster="poster.webp" shadow-intensity="1" ar-status="not-presenting">
<!--?lit$128424273$--><!---->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay, now it builds, but these tests still fail - have you been running them locally? Also, do you understand what this is testing? Because it appears you removed the exact thing the test was checking gets removed properly, which I think means this test isn't really doing anything anymore. And it also implies to me that your PR is in fact causing a regression that this test was correctly checking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @elalish Thanks For Reviewing Again
I also Don't Understand what's the Problem arising it's still fails test for recognition of innertext instead of innerhtml

Thanks

Copy link
Collaborator

Choose a reason for hiding this comment

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

May I ask what brought you to our repo? I'm getting the impression that you don't fully understand the difference between innerText and innerHTML, which are not drop-in replacements for each other.

<div class="progress-bar hide" slot="progress-bar">
<div class="update-bar"></div>
</div><!----><!---->
<button slot="ar-button" id="ar-button">
View in your space
</button><!----><!---->
<div id="ar-prompt">
<img>
</div><!---->
snippetViewer.renderedSnippet = html`<model-viewer src="Astronaut.glb" ar="" camera-controls="" poster="poster.webp" shadow-intensity="1" ar-status="not-presenting">
<div class="progress-bar hide" slot="progress-bar">
<div class="update-bar"></div>
</div>
<button slot="ar-button" id="ar-button">
View in your space
</button>
<div id="ar-prompt">
<img>
</div>
</model-viewer>`;
// clang-format on

const goldenFormattedHTML =
`<model-viewer src="Astronaut.glb" ar camera-controls poster="poster.webp" shadow-intensity="1">
Expand All @@ -71,23 +66,20 @@ View in your space
});

test('formatted HTML does not greedily strip comments', async () => {
// clang-format off

// Pulled from real DOM of astronaut example with a hotspot.
// hotspot <button> is beteen two comments on the same line
snippetViewer.renderedSnippet = html`<!--?lit$128424273$--><model-viewer src="Astronaut.glb" ar="" camera-controls="" poster="poster.webp" shadow-intensity="1" ar-status="not-presenting">
<!--?lit$128424273$--><!----><button class="Hotspot" slot="hotspot-1" data-position="-0.043973778464142396m 1.2075171453793048m 0.29653766978435936m" data-normal="-0.4260645307016329m -0.06968452861538316m 0.9020050344369756m" data-visibility-attribute="visible"><div class="HotspotAnnotation">asdf</div></button><!----><!---->
<div class="progress-bar hide" slot="progress-bar">
<div class="update-bar"></div>
</div><!----><!---->
<button slot="ar-button" id="ar-button">
View in your space
</button><!----><!---->
<div id="ar-prompt">
<img>
</div><!---->
snippetViewer.renderedSnippet = html`<model-viewer src="Astronaut.glb" ar="" camera-controls="" poster="poster.webp" shadow-intensity="1" ar-status="not-presenting">
<button class="Hotspot" slot="hotspot-1" data-position="-0.043973778464142396m 1.2075171453793048m 0.29653766978435936m" data-normal="-0.4260645307016329m -0.06968452861538316m 0.9020050344369756m" data-visibility-attribute="visible">
<div class="HotspotAnnotation">asdf</div>
</button>
<div class="progress-bar hide" slot="progress-bar">
<div class="update-bar"></div>
</div>
<button slot="ar-button" id="ar-button">
View in your space
</button>
<div id="ar-prompt">
<img>
</div>
</model-viewer>`;
// clang-format on

const goldenFormattedHTML =
`<model-viewer src="Astronaut.glb" ar camera-controls poster="poster.webp" shadow-intensity="1">
Expand Down