question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Code removed from output

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

1reaction
simmerercommented, Jul 30, 2020

We’re using lowlight=1.14.0 now, so this is resolved in react-syntax-highlighter 13.0.0+

Try it here in the updated demo: https://react-syntax-highlighter.github.io/react-syntax-highlighter/demo/prism.html

1reaction
Rogdhamcommented, Jan 2, 2020

In the meanwhile, a workaround is to use Yarn’s resolution feature by adding the following to package.json:

  "resolutions": {
    "react-syntax-highlighter": "12.2.1"
  },
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found