Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7c79cc3

Browse files
committed
Fix parsing body lines starting with --- and +++
1 parent730dccf commit7c79cc3

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

‎src/diff-parser.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@
183183
(
184184
currentFile&&// If we already have some file in progress and
185185
(
186-
currentFile.oldName&&utils.startsWith(line,'---')||// Either we reached a old file identification line
187-
currentFile.newName&&utils.startsWith(line,'+++')// Or we reached a new file identification line
186+
currentFile.oldName&&utils.startsWith(line,'---')||// Either we reached a old file identification line
187+
currentFile.newName&&utils.startsWith(line,'+++')// Or we reached a new file identification line
188188
)
189189
)
190190
){
@@ -198,7 +198,7 @@
198198
* --- 2002-02-21 23:30:39.942229878 -0800
199199
*/
200200
if(currentFile&&!currentFile.oldName&&
201-
utils.startsWith(line,'---')&&(values=getSrcFilename(line,config))){
201+
utils.startsWith(line,'---')&&(values=getSrcFilename(line,config))){
202202
currentFile.oldName=values;
203203
currentFile.language=getExtension(currentFile.oldName,currentFile.language);
204204
return;
@@ -209,7 +209,7 @@
209209
* +++ 2002-02-21 23:30:39.942229878 -0800
210210
*/
211211
if(currentFile&&!currentFile.newName&&
212-
utils.startsWith(line,'+++')&&(values=getDstFilename(line,config))){
212+
utils.startsWith(line,'+++')&&(values=getDstFilename(line,config))){
213213
currentFile.newName=values;
214214
currentFile.language=getExtension(currentFile.newName,currentFile.language);
215215
return;

‎test/diff-parser-tests.js‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,34 @@ describe('DiffParser', function() {
424424
assert.deepEqual(linesContent,['-test','+test1r','+test2r']);
425425
});
426426

427+
it('should parse diff with --- and +++ in the context lines',function(){
428+
vardiff=
429+
'--- sample.js\n'+
430+
'+++ sample.js\n'+
431+
'@@ -1,15 +1,12 @@\n'+
432+
' test\n'+
433+
' \n'+
434+
'----\n'+
435+
'+test\n'+
436+
' \n'+
437+
' test\n'+
438+
'----\n'+
439+
'\\ No newline at end of file';
440+
441+
varresult=DiffParser.generateDiffJson(diff);
442+
varfile1=result[0];
443+
assert.equal(1,result.length);
444+
assert.equal(1,file1.addedLines);
445+
assert.equal(2,file1.deletedLines);
446+
assert.equal('sample.js',file1.oldName);
447+
assert.equal('sample.js',file1.newName);
448+
assert.equal(1,file1.blocks.length);
449+
450+
varlinesContent=file1.blocks[0].lines.map(function(line){
451+
returnline.content;
452+
});
453+
assert.deepEqual(linesContent,[' test',' ','----','+test',' ',' test','----']);
454+
});
455+
427456
});
428457
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp