diff --git a/index.js b/index.js index 7b8d7b8..4a2e61d 100644 --- a/index.js +++ b/index.js @@ -32,7 +32,8 @@ const yamlParser = (str = "") => { level = level - 1; } const isArrayItem = line.trim().startsWith("-"); - let [key, value] = line.trim().split(":").map(v => v.trim()); + // TODO: improve the regex to capture the line structure + let [_, key, value] = (line.trim().match(/^([^:"]*):(.*)$/m) || ["", line]).map(v => v.trim()); // Check if is a new item of the array if (isArrayItem) { key = key.replace(/^(- *)/m, ""); diff --git a/test.js b/test.js index a0f444e..d1c6d20 100644 --- a/test.js +++ b/test.js @@ -376,6 +376,20 @@ describe("utils", () => { assert.equal(json.items[2].items[1], "bar"); assert.equal(json.foo, "bar"); }); + + it("should support ':' characters in value", () => { + const json = yaml([ + `link1: "https://www.example1.com"`, + `link2: "https://www.example2.com"`, + `items:`, + ` - "https://www.example3.com"`, + ` - key: "https://www.example4.com"`, + ]); + assert.equal(json.link1, "https://www.example1.com"); + assert.equal(json.link2, "https://www.example2.com"); + assert.equal(json.items[0], "https://www.example3.com"); + assert.equal(json.items[1].key, "https://www.example4.com"); + }); }); describe("frontmatter", () => {