Kaynağa Gözat

Merge pull request #3200 from shockey/bug/3199-sanitization-escaping

Markdown quote double-escaping
bubble
shockey 7 yıl önce
committed by GitHub
ebeveyn
işleme
e7975e7f3d
4 değiştirilmiş dosya ile 33 ekleme ve 3 silme
  1. +1
    -1
      .eslintrc
  2. +1
    -1
      package.json
  3. +8
    -1
      src/core/components/providers/markdown.jsx
  4. +23
    -0
      test/bugs/3199-sanitization-escaping.js

+ 1
- 1
.eslintrc Dosyayı Görüntüle

@@ -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,


+ 1
- 1
package.json Dosyayı Görüntüle

@@ -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",


+ 8
- 1
src/core/components/providers/markdown.jsx Dosyayı Görüntüle

@@ -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
- 0
test/bugs/3199-sanitization-escaping.js Dosyayı Görüntüle

@@ -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("{&quot;abc&quot;: &quot;def&quot;}\n")
})
})

Yükleniyor…
İptal
Kaydet