Skip to content

Commit

Permalink
Revert fix introduced in d462f04, which is now properly handled thank…
Browse files Browse the repository at this point in the history
…s to 1101370 (Fixes #59)
  • Loading branch information
eemeli committed Dec 13, 2018
1 parent b16d410 commit 80b78be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
16 changes: 16 additions & 0 deletions __tests__/foldFlowLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,22 @@ describe('double-quoted', () => {
expect(doc.contents.items[0].items[0].value.value).toBe(key2)
})
})

describe('eemeli/yaml#59', () => {
test('minimal', () => {
const str = `"######\\\\P#"`
expect(fold(str, '', FOLD_QUOTED, options)).toBe(`"######\\\\\\\nP#"`)
})

test('reported', () => {
const value =
'>####################################"##########################\'####\\P#'
const str = YAML.stringify({ key: [[value]] })
const doc = YAML.parseDocument(str)
expect(doc.errors).toHaveLength(0)
expect(doc.contents.items[0].value.items[0].items[0].value).toBe(value)
})
})
})

describe('end-to-end', () => {
Expand Down
9 changes: 2 additions & 7 deletions src/foldFlowLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,8 @@ export default function foldFlowLines(
for (let i = 0; i < folds.length; ++i) {
const fold = folds[i]
const end = folds[i + 1] || text.length
if (mode === FOLD_QUOTED && escapedFolds[fold]) {
const ch = text[fold]
res += ch === '\\' ? `\\\n${indent}${ch}` : `${ch}\\\n${indent}`
} else {
res += `\n${indent}`
}
res += text.slice(fold + 1, end)
if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`
res += `\n${indent}${text.slice(fold + 1, end)}`
}
return res
}

0 comments on commit 80b78be

Please sign in to comment.