Skip to content

strings in the output of highlight function with html: true maybe malformed #90

@SidneyTTW

Description

@SidneyTTW

Describe the bug
strings in the output of highlight function with html: true maybe malformed when the sql query contains special characters in hardcoded string
It seems that the special characters should be escaped in the output

To Reproduce
Steps to reproduce the behavior:

  • Use code below
const { highlight } = require('sql-highlight')
let sqlString = "select * from a where b = 'array<map<string,string>>';"
let highlighted = highlight(sqlString, { html: true })
console.log(highlighted)
  • And execute it with nodejs

Actual behavior

  • It prints
    <span class="sql-hl-keyword">select</span> <span class="sql-hl-special">*</span> <span class="sql-hl-keyword">from</span> a <span class="sql-hl-keyword">where</span> b <span class="sql-hl-special">=</span> <span class="sql-hl-string">'array<map<string,string>>'</span><span class="sql-hl-special">;</span>
  • And if I try to put the 'array<map<string,string>>' into html
    The browser will treat it as
    image
    And user will see
    image

Expected behavior

  • It prints
    <span class="sql-hl-keyword">select</span> <span class="sql-hl-special">*</span> <span class="sql-hl-keyword">from</span> a <span class="sql-hl-keyword">where</span> b <span class="sql-hl-special">=</span> <span class="sql-hl-string">'array&ltmap&ltstring,string&gt&gt'</span><span class="sql-hl-special">;</span>
  • And if I put the 'array&ltmap&ltstring,string&gt&gt' into html
    The browser will treat it as
    image
    And user will see
    image

Node.js (please complete the following information):

  • Version v16.17.1

Browser (please complete the following information):

  • OS: MacOS
  • Browser Chrome
  • Version 108.0.5359.124

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions