From a07b276d23db95402f05d3fd41c849fe397d724a Mon Sep 17 00:00:00 2001 From: Mike Gilbode Date: Mon, 23 Oct 2017 15:02:41 -0400 Subject: [PATCH 1/4] Upgrade to react 15.6.2. --- package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index dbaa1c80..bacb0512 100644 --- a/package.json +++ b/package.json @@ -55,12 +55,12 @@ "memoizee": "0.4.1", "promise-worker": "^1.1.1", "prop-types": "^15.5.10", - "react": "^15.4.0", + "react": "^15.6.2", "react-addons-perf": "^15.4.0", "react-addons-shallow-compare": "0.14.8", - "react-addons-test-utils": "^15.4.0", + "react-addons-test-utils": "^15.6.2", "react-collapse": "2.3.1", - "react-dom": "^15.4.0", + "react-dom": "^15.6.2", "react-height": "^2.0.0", "react-hot-loader": "1.3.1", "react-immutable-proptypes": "2.1.0", From f600fe8dbba6e44424dba064a505760dfeedd262 Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Wed, 1 Nov 2017 21:48:18 -0400 Subject: [PATCH 2/4] Simplify formatXml --- src/core/utils.js | 29 +++++++++++------------------ test/core/utils.js | 14 +++++++++++++- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 0f247b52..c9435715 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -186,24 +186,17 @@ export function formatXml (xml) { "other->other": 0 } fn = function(ln) { - var fromTo, key, padding, type, types, value - types = { - single: Boolean(ln.match(/<.+\/>/)), - closing: Boolean(ln.match(/<\/.+>/)), - opening: Boolean(ln.match(/<[^!?].*>/)) - } - type = ((function() { - var results - results = [] - for (key in types) { - value = types[key] - if (value) { - results.push(key) - } - } - return results - })())[0] - type = type === void 0 ? "other" : type + var fromTo, padding, type + + if (Boolean(ln.match(/<.+\/>/))) { + type = "single" + } else if (Boolean(ln.match(/<\/.+>/))) { + type = "closing" + } else if (Boolean(ln.match(/<[^!?].*>/))) { + type = "opening" + } else { + type = "other" + } fromTo = lastType + "->" + type lastType = type padding = "" diff --git a/test/core/utils.js b/test/core/utils.js index dd37a518..1f027b96 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -16,7 +16,8 @@ import { fromJSOrdered, getAcceptControllingResponse, createDeepLinkPath, - escapeDeepLinkPath + escapeDeepLinkPath, + formatXml } from "core/utils" import win from "core/window" @@ -885,4 +886,15 @@ describe("utils", function() { expect(result).toEqual("hello\\#world") }) }) + + describe("formatXml", function() { + it("simple xml formatting", function() { + const startTime = Date.now() + const result = formatXml("john doe") + let duration = Date.now() - startTime + expect(result).toEqual("\n john doe\n\n") + expect(duration).toBeLessThan(5) + }) + }) + }) From 034ebb021cf65d9dc72f141e181f4909edcab390 Mon Sep 17 00:00:00 2001 From: HelderSepu Date: Wed, 1 Nov 2017 22:00:28 -0400 Subject: [PATCH 3/4] Remove redundant Boolean call --- src/core/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index ab36a3b4..6f72b9c0 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -188,11 +188,11 @@ export function formatXml (xml) { fn = function(ln) { var fromTo, padding, type - if (Boolean(ln.match(/<.+\/>/))) { + if (ln.match(/<.+\/>/)) { type = "single" - } else if (Boolean(ln.match(/<\/.+>/))) { + } else if (ln.match(/<\/.+>/)) { type = "closing" - } else if (Boolean(ln.match(/<[^!?].*>/))) { + } else if (ln.match(/<[^!?].*>/)) { type = "opening" } else { type = "other" From 17e6d815049c9ddd385c2df419f4720807e4fbdc Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Thu, 2 Nov 2017 15:13:10 -0700 Subject: [PATCH 4/4] Format XML with `xml-but-prettier` --- package.json | 1 + src/core/components/response-body.jsx | 6 ++- src/core/utils.js | 70 --------------------------- test/core/utils.js | 11 ----- 4 files changed, 5 insertions(+), 83 deletions(-) diff --git a/package.json b/package.json index 50a0a51d..17ba6a80 100644 --- a/package.json +++ b/package.json @@ -84,6 +84,7 @@ "whatwg-fetch": "0.11.1", "worker-loader": "^0.7.1", "xml": "1.0.1", + "xml-but-prettier": "^1.0.1", "yaml-js": "0.2.0" }, "devDependencies": { diff --git a/src/core/components/response-body.jsx b/src/core/components/response-body.jsx index c55c1d6d..e3c2aeb1 100644 --- a/src/core/components/response-body.jsx +++ b/src/core/components/response-body.jsx @@ -1,6 +1,6 @@ import React from "react" import PropTypes from "prop-types" -import { formatXml } from "core/utils" +import formatXml from "xml-but-prettier" import lowerCase from "lodash/lowerCase" export default class ResponseBody extends React.Component { @@ -31,7 +31,9 @@ export default class ResponseBody extends React.Component { // XML } else if (/xml/i.test(contentType)) { - body = formatXml(content) + body = formatXml(content, { + textNodesOnSameLine: true + }) bodyEl = // HTML or Plain Text diff --git a/src/core/utils.js b/src/core/utils.js index 6f72b9c0..6ac9eb29 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -155,76 +155,6 @@ export function getList(iterable, keys) { return Im.List.isList(val) ? val : Im.List() } -// Adapted from http://stackoverflow.com/a/2893259/454004 -// Note: directly ported from CoffeeScript -export function formatXml (xml) { - var contexp, fn, formatted, indent, l, lastType, len, lines, ln, reg, transitions, wsexp - reg = /(>)(<)(\/*)/g - wsexp = /[ ]*(.*)[ ]+\n/g - contexp = /(<.+>)(.+\n)/g - xml = xml.replace(/\r\n/g, "\n").replace(reg, "$1\n$2$3").replace(wsexp, "$1\n").replace(contexp, "$1\n$2") - formatted = "" - lines = xml.split("\n") - indent = 0 - lastType = "other" - transitions = { - "single->single": 0, - "single->closing": -1, - "single->opening": 0, - "single->other": 0, - "closing->single": 0, - "closing->closing": -1, - "closing->opening": 0, - "closing->other": 0, - "opening->single": 1, - "opening->closing": 0, - "opening->opening": 1, - "opening->other": 1, - "other->single": 0, - "other->closing": -1, - "other->opening": 0, - "other->other": 0 - } - fn = function(ln) { - var fromTo, padding, type - - if (ln.match(/<.+\/>/)) { - type = "single" - } else if (ln.match(/<\/.+>/)) { - type = "closing" - } else if (ln.match(/<[^!?].*>/)) { - type = "opening" - } else { - type = "other" - } - fromTo = lastType + "->" + type - lastType = type - padding = "" - indent += transitions[fromTo] - padding = ((function() { - /* eslint-disable no-unused-vars */ - var m, ref1, results, j - results = [] - for (j = m = 0, ref1 = indent; 0 <= ref1 ? m < ref1 : m > ref1; j = 0 <= ref1 ? ++m : --m) { - results.push(" ") - } - /* eslint-enable no-unused-vars */ - return results - })()).join("") - if (fromTo === "opening->closing") { - formatted = formatted.substr(0, formatted.length - 1) + ln + "\n" - } else { - formatted += padding + ln + "\n" - } - } - for (l = 0, len = lines.length; l < len; l++) { - ln = lines[l] - fn(ln) - } - return formatted -} - - /** * Adapted from http://github.com/asvd/microlight * @copyright 2016 asvd diff --git a/test/core/utils.js b/test/core/utils.js index e50eb092..1068aab4 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -17,7 +17,6 @@ import { getAcceptControllingResponse, createDeepLinkPath, escapeDeepLinkPath, - formatXml, sanitizeUrl } from "core/utils" import win from "core/window" @@ -888,16 +887,6 @@ describe("utils", function() { }) }) - describe("formatXml", function() { - it("simple xml formatting", function() { - const startTime = Date.now() - const result = formatXml("john doe") - let duration = Date.now() - startTime - expect(result).toEqual("\n john doe\n\n") - expect(duration).toBeLessThan(5) - }) - }) - describe("sanitizeUrl", function() { it("should sanitize a `javascript:` url", function() { const res = sanitizeUrl("javascript:alert('bam!')")