Merge pull request #3200 from shockey/bug/3199-sanitization-escaping
Markdown quote double-escaping
This commit is contained in:
@@ -22,7 +22,7 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"semi": [2, "never"],
|
"semi": [2, "never"],
|
||||||
"strict": 0,
|
"strict": 0,
|
||||||
"quotes": 2,
|
"quotes": [2, "double", { "allowTemplateLiterals": true }],
|
||||||
"no-unused-vars": 2,
|
"no-unused-vars": 2,
|
||||||
"no-multi-spaces": 1,
|
"no-multi-spaces": 1,
|
||||||
"camelcase": 1,
|
"camelcase": 1,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
"test": "npm run lint-errors && npm run just-test-in-node",
|
"test": "npm run lint-errors && npm run just-test-in-node",
|
||||||
"test-in-node": "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": "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": {
|
"dependencies": {
|
||||||
"babel-polyfill": "^6.23.0",
|
"babel-polyfill": "^6.23.0",
|
||||||
|
|||||||
@@ -2,8 +2,15 @@ import React, { PropTypes } from "react"
|
|||||||
import Remarkable from "react-remarkable"
|
import Remarkable from "react-remarkable"
|
||||||
import sanitize from "sanitize-html"
|
import sanitize from "sanitize-html"
|
||||||
|
|
||||||
|
const sanitizeOptions = {
|
||||||
|
textFilter: function(text) {
|
||||||
|
return text
|
||||||
|
.replace(/"/g, "\"")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Markdown({ source }) {
|
function Markdown({ source }) {
|
||||||
const sanitized = sanitize(source)
|
const sanitized = sanitize(source, sanitizeOptions)
|
||||||
return <Remarkable
|
return <Remarkable
|
||||||
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
options={{html: true, typographer: true, linkify: true, linkTarget: "_blank"}}
|
||||||
source={sanitized}
|
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