Merge pull request #3200 from shockey/bug/3199-sanitization-escaping
Markdown quote double-escaping
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
"rules": {
|
||||
"semi": [2, "never"],
|
||||
"strict": 0,
|
||||
"quotes": 2,
|
||||
"quotes": [2, "double", { "allowTemplateLiterals": true }],
|
||||
"no-unused-vars": 2,
|
||||
"no-multi-spaces": 1,
|
||||
"camelcase": 1,
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
"test": "npm run lint-errors && npm run just-test-in-node",
|
||||
"test-in-node": "npm run lint-errors && npm run just-test-in-node",
|
||||
"just-test": "karma start --config karma.conf.js",
|
||||
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components"
|
||||
"just-test-in-node": "mocha --recursive --compilers js:babel-core/register test/core test/components test/bugs"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-polyfill": "^6.23.0",
|
||||
|
||||
@@ -2,8 +2,15 @@ import React, { PropTypes } from "react"
|
||||
import Remarkable from "react-remarkable"
|
||||
import sanitize from "sanitize-html"
|
||||
|
||||
const sanitizeOptions = {
|
||||
textFilter: function(text) {
|
||||
return text
|
||||
.replace(/"/g, "\"")
|
||||
}
|
||||
}
|
||||
|
||||
function Markdown({ source }) {
|
||||
const sanitized = sanitize(source)
|
||||
const sanitized = sanitize(source, sanitizeOptions)
|
||||
return <Remarkable
|
||||
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
||||
source={sanitized}
|
||||
|
||||
23
test/bugs/3199-sanitization-escaping.js
Normal file
23
test/bugs/3199-sanitization-escaping.js
Normal file
@@ -0,0 +1,23 @@
|
||||
/* eslint-env mocha */
|
||||
import React from "react"
|
||||
import expect from "expect"
|
||||
import { render } from "enzyme"
|
||||
import Markdown from "components/providers/markdown"
|
||||
|
||||
describe("UI-3199: Sanitized Markdown causing code examples to be double escaped", function(){
|
||||
it("should single-escape quotes", function(){
|
||||
|
||||
let str = "" +
|
||||
"This is a test: \n\n" +
|
||||
" {\"abc\": \"def\"}\n"
|
||||
|
||||
let props = {
|
||||
source: str
|
||||
}
|
||||
|
||||
let el = render(<Markdown {...props}/>)
|
||||
|
||||
expect(el.find("code").first().text()).toEqual("{\"abc\": \"def\"}\n")
|
||||
expect(el.find("code").first().html()).toEqual("{"abc": "def"}\n")
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user