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
forked fromkpdecker/jsdiff

Commit3ab1df8

Browse files
committed
Less restrictive regexp & 'should handle patches without Index' test
1 parente9a40c3 commit3ab1df8

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

‎src/patch/parse.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function parsePatch(uniDiff, options = {}) {
2525
i++;
2626
}
2727

28+
// Parse file headers if they are defined. Unified diff requires them, but
29+
// there's no technical issues to have an isolated hunk without file header
2830
parseFileHeader(index);
2931
parseFileHeader(index);
3032

@@ -36,7 +38,7 @@ export function parsePatch(uniDiff, options = {}) {
3638

3739
if(/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(line)){
3840
break;
39-
}elseif(/^@@\s/.test(line)){
41+
}elseif(/^@@/.test(line)){
4042
index.hunks.push(parseHunk());
4143
}elseif(line&&options.strict){
4244
// Ignore unexpected content unless in strict mode
@@ -50,7 +52,7 @@ export function parsePatch(uniDiff, options = {}) {
5052
// Parses the --- and +++ headers, if none are found, no lines
5153
// are consumed.
5254
functionparseFileHeader(index){
53-
letfileHeader=(/^(\-\-\-|\+\+\+)\s+(\S+)\s?(.+)/).exec(diffstr[i]);
55+
letfileHeader=(/^(\-\-\-|\+\+\+)\s+(\S+)\s?(.+?)\s*$/).exec(diffstr[i]);
5456
if(fileHeader){
5557
letkeyPrefix=fileHeader[1]==='---' ?'old' :'new';
5658
index[keyPrefix+'FileName']=fileHeader[2];

‎test/patch/apply.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,5 +554,36 @@ describe('patch/apply', function() {
554554
}
555555
});
556556
});
557+
it('should handle patches without Index',function(done){
558+
constpatch=
559+
'===================================================================\n'
560+
+'--- test\theader1\n'
561+
+'+++ test\theader2\n'
562+
+'@@ -1,3 +1,4 @@\n'
563+
+' line2\n'
564+
+' line3\n'
565+
+'+line4\n'
566+
+' line5\n'
567+
+'===================================================================\n'
568+
+'--- test2\theader1\n'
569+
+'+++ test2\theader2\n'
570+
+'@@ -1,3 +1,4 @@\n'
571+
+' foo2\n'
572+
+' foo3\n'
573+
+'+foo4\n'
574+
+' foo5\n';
575+
576+
applyPatches(patch,{
577+
loadFile(index,callback){
578+
callback(undefined,contents[index.oldFileName]);
579+
},
580+
patched(index,content){
581+
expect(content)
582+
.to.equal(expected[index.newFileName])
583+
.to.not.be.undefined;
584+
},
585+
complete:done
586+
});
587+
});
557588
});
558589
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp