Skip to content

Commit

Permalink
check file extension is .html before injecting HTML scripts (#5944)
Browse files Browse the repository at this point in the history
## Summary

- follow-up to #5766
- part of addressing #4276

Thank you @testlabauto for noticing the test failures in main!

Plots were failing to display for the highcharter and plotly R examples,
and errors would be seen in the dev tools console:


![image](https://github.com/user-attachments/assets/266c121b-4593-4795-996d-700e1e1ad417)

@:plots

### Implementation

- check that the file is an HTML file before injecting the HTML scripts
- the `Uncaught SyntaxError: Unexpected token '<'` error was occurring
because we were injecting HTML into javascript files (oops!)

### Release Notes

#### New Features

- N/A

#### Bug Fixes

- N/A


### QA Notes

The
[highcharter](https://github.com/posit-dev/qa-example-content/blob/main/workspaces/r-plots/highcharter-example.r)
and
[plotly](https://github.com/posit-dev/qa-example-content/blob/main/workspaces/r-plots/plotly-example.r)
R examples should work in Positron Server Web.
  • Loading branch information
sharon-wang authored Jan 10, 2025
1 parent c73f15a commit 45ac6c1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions extensions/positron-proxy/src/htmlProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ export class HtmlProxyServer implements Disposable {
const filePath = path.join(targetPath, req.path);
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
let content = fs.readFileSync(filePath, 'utf8');
// If there is an HTML configuration, use it to rewrite the content.
if (htmlConfig) {
const fileExt = path.extname(filePath).toLowerCase();
const isHtmlFile = ['.html', '.htm'].includes(fileExt);

// If the file is an HTML file and we have an HTML configuration, inject the
// preview resources into the HTML content.
if (isHtmlFile && htmlConfig) {
content = injectPreviewResources(content, htmlConfig);
}
res.send(content);
Expand Down

0 comments on commit 45ac6c1

Please sign in to comment.