Code removed from output
See original GitHub issueDescribe the bug
Highlighting the following code as html
results in the alert()
part being removed:
<script>alert()</script>
becomes
<script></script>
To Reproduce
JSX
import SyntaxHighlighter from 'react-syntax-highlighter';
const code = `<script>alert()</script>`;
const element = <SyntaxHighlighter language="html">{code}</SyntaxHighlighter>;
Node.js
Let’s use babel to transcode the following:
import React from "react";
import renderer from "react-test-renderer";
import SyntaxHighlighter from "react-test-renderer";
const code = `<script>alert()</script>`;
const tree = renderer
.create(<SyntaxHighlighter language="html">{code}</SyntaxHighlighter>)
.toJSON();
console.log(JSON.stringify(tree, undefined, 2));
into:
"use strict";
var react = _interopRequireDefault(require("react"));
var reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
var reactSyntaxHighlighter = _interopRequireDefault(
require("react-syntax-highlighter")
);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
var code = "<script>alert()</script>";
var tree = reactTestRenderer.default
.create(
react.default.createElement(
reactSyntaxHighlighter.default,
{
language: "html"
},
code
)
)
.toJSON();
console.log(JSON.stringify(tree, undefined, 2));
When running this script with Node.js (provided react-test-renderer is installed as well), it outputs:
{
"type": "pre",
"props": {
"style": {
"display": "block",
"overflowX": "auto",
"padding": "0.5em",
"background": "#F0F0F0",
"color": "#444"
}
},
"children": [
{
"type": "code",
"props": {},
"children": [
{
"type": "span",
"props": {
"className": "hljs-tag",
"style": {}
},
"children": [
"<",
{
"type": "span",
"props": {
"style": {
"fontWeight": "bold"
}
},
"children": [
"script"
]
},
">"
]
},
{
"type": "span",
"props": {
"className": "null",
"style": {}
},
"children": null
},
{
"type": "span",
"props": {
"className": "hljs-tag",
"style": {}
},
"children": [
"</",
{
"type": "span",
"props": {
"style": {
"fontWeight": "bold"
}
},
"children": [
"script"
]
},
">"
]
}
]
}
]
}
as you can see, the alert()
part is replaced with:
{
"type": "span",
"props": {
"className": "null",
"style": {}
},
"children": null
},
Expected behavior
The output should still have alert()
from the input.
Desktop (please complete the following information):
- OS: ArchLinux
- Browser: tested with Firefox 68.0.2 and Chrome76.0.3809.100
- Version: react-syntax-highlighter 11.0.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
How to remove unwanted terminal output of vscode for ...
How to remove unwanted terminal output of vscode for window11 ... -Open Visual Studio Code and press F1 to open the command panel...
Read more >How to remove "exited with code 0." from cmd console
The output on the console prints up fine, but then is followed by: C:\Users\...\MyProgram.exe (process 17008) exited with code 0. and ends with:...
Read more >java - Remove Text Appearing before the Program Output
Background: I'm running JDK 16 on WSL2 and using VScode on windows. I have java essential Java Vscode extensions installed. The problem is, ......
Read more >Remove + from output - WordPress.org
Another way is to remove the symbol before the mail processing. To achieve this you can use this code in the functions.php file...
Read more >Option to remove output info · Issue #24 - GitHub
It would be useful have a setting to remove the pre ([Running]) and post ([Done]) labels in the output console.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We’re using
lowlight=1.14.0
now, so this is resolved inreact-syntax-highlighter
13.0.0+Try it here in the updated demo: https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html
In the meanwhile, a workaround is to use Yarn’s resolution feature by adding the following to
package.json
: