fix: handle optional semi-colon in the end of xml style attributes

This commit is contained in:
Mikael Sand
2019-08-26 15:51:52 +03:00
parent a7c92c62a1
commit 6523a17157
+26 -13
View File
@@ -139,12 +139,16 @@ const camelCase = phrase => phrase.replace(/-([a-z])/g, upperCase);
export function getStyle(string) { export function getStyle(string) {
const style = {}; const style = {};
const declarations = string.split(";"); const declarations = string.split(";");
for (let i = 0, l = declarations.length; i < l; i++) { const { length } = declarations;
const declaration = declarations[i].split(":"); for (let i = 0; i < length; i++) {
const property = declaration[0]; const declaration = declarations[i];
const value = declaration[1]; if (declaration.length !== 0) {
const split = declaration.split(":");
const property = split[0];
const value = split[1];
style[camelCase(property.trim())] = value.trim(); style[camelCase(property.trim())] = value.trim();
} }
}
return style; return style;
} }
@@ -164,7 +168,8 @@ export function astToReact(child, i) {
function locate(source, search) { function locate(source, search) {
const lines = source.split("\n"); const lines = source.split("\n");
for (let line = 0, l = lines.length; line < l; line++) { const nLines = lines.length;
for (let line = 0; line < nLines; line++) {
const { length } = lines[line]; const { length } = lines[line];
if (search < length) { if (search < length) {
return { line, column: search }; return { line, column: search };
@@ -213,8 +218,8 @@ export function parse(source) {
function metadata() { function metadata() {
while ( while (
(i < length && source[i] !== "<") || i + 1 < length &&
!validNameCharacters.test(source[i + 1]) (source[i] !== "<" || !validNameCharacters.test(source[i + 1]))
) { ) {
i++; i++;
} }
@@ -224,7 +229,11 @@ export function parse(source) {
function neutral() { function neutral() {
let text = ""; let text = "";
while (i < length && source[i] !== "<") text += source[i++]; let char;
while (i < length && (char = source[i]) !== "<") {
text += char;
i += 1;
}
if (/\S/.test(text)) { if (/\S/.test(text)) {
children.push(text); children.push(text);
@@ -243,9 +252,10 @@ export function parse(source) {
if (char === "?") return neutral; // <?xml... if (char === "?") return neutral; // <?xml...
if (char === "!") { if (char === "!") {
if (source.slice(i + 1, i + 3) === "--") return comment; let start = i + 1;
if (source.slice(i + 1, i + 8) === "[CDATA[") return cdata; if (source.slice(start, i + 3) === "--") return comment;
if (/doctype/i.test(source.slice(i + 1, i + 8))) return neutral; if (source.slice(start, i + 8) === "[CDATA[") return cdata;
if (/doctype/i.test(source.slice(start, i + 8))) return neutral;
} }
if (char === "/") return closingTag; if (char === "/") return closingTag;
@@ -336,8 +346,11 @@ export function parse(source) {
function getName() { function getName() {
let name = ""; let name = "";
while (i < length && validNameCharacters.test(source[i])) let char;
name += source[i++]; while (i < length && validNameCharacters.test((char = source[i]))) {
name += char;
i += 1;
}
return name; return name;
} }