Skip to content

Commit

Permalink
Fix to prevent insertion of double line endings. Tests changed accord…
Browse files Browse the repository at this point in the history
…ingly
  • Loading branch information
bkp7 committed Feb 13, 2018
1 parent 7db4808 commit b8297be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/processFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ export function processText (txt, clear, fileDirName) {
} else {
if (clear !== true) {
r = r + h.replaceLineEndings(t.prepend + runCliCmd(t.info.cliCommand, fileDirName) + t.postpend, eolIsCRLF)
} else {
// we are clearing any content so remove all lines between the start and end lines
}
if (r.substr(-1) === '\n') {
// we don't want to introduce 2 CRLFs or LFs so remove all lines between the start and end lines
if (txt.substr(frm, 1) === '\r') { frm++ }
/* istanbul ignore else */
if (txt.substr(frm, 1) === '\n') { frm++ }
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
name: 'Command Line invalid',
text: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\n12345\r\n[<]: #\r\n',
clear: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\n[<]: #\r\n',
full_win: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\r\n\'catt\' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n\r\n[<]: #\r\n',
full_linux: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\r\n/bin/sh: 1: catt: not found\r\n\r\n[<]: #\r\n'
full_win: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\r\n\'catt\' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n[<]: #\r\n',
full_linux: '[>]: # (mdpInsert catt test/docs/abc.txt)\r\nERROR: Command failed: catt test/docs/abc.txt\r\n/bin/sh: 1: catt: not found\r\n[<]: #\r\n'
}, {
name: 'Surrounded',
text: '# Simple Test\r\nSome initial text.\r\n[>]: # (mdpInsert cat test/docs/abc.txt)\r\nold text\r\n[<]: #\r\nOther text',
Expand Down Expand Up @@ -186,8 +186,8 @@
name: 'Missing File',
text: '[>]: # (mdpInsert cat file/not/present.txt)\r\n12345\r\n[<]: #\r\n',
clear: '[>]: # (mdpInsert cat file/not/present.txt)\r\n[<]: #\r\n',
full_win: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: type file\\not\\present.txt\r\nThe system cannot find the path specified.\r\n\r\n[<]: #\r\n',
full_linux: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: cat file/not/present.txt\r\ncat: file/not/present.txt: No such file or directory\r\n\r\n[<]: #\r\n'
full_win: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: type file\\not\\present.txt\r\nThe system cannot find the path specified.\r\n[<]: #\r\n',
full_linux: '[>]: # (mdpInsert cat file/not/present.txt)\r\nERROR: Command failed: cat file/not/present.txt\r\ncat: file/not/present.txt: No such file or directory\r\n[<]: #\r\n'
}
]

Expand Down

0 comments on commit b8297be

Please sign in to comment.