File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,15 +179,15 @@ function decodeTag(body: Uint8Array): TagObject {
179179 } ;
180180}
181181
182- function decodePerson ( string : string ) {
183- const match = string . match ( / ^ ( [ ^ < ] * ) < ( [ ^ > ] * ) > ( [ ^ ] * ) ( .* ) $ / ) ;
182+ function decodePerson ( string : string ) : Person {
183+ const match = string . match ( / ^ (?: ( [ ^ < ] * ) ) ? < ( [ ^ > ] * ) > ( [ ^ ] * ) ( .* ) $ / ) ;
184184 if ( ! match ) throw new Error ( 'Improperly formatted person string' ) ;
185185 return {
186- name : match [ 1 ] ,
187- email : match [ 2 ] ,
186+ name : match [ 1 ] ?? `` ,
187+ email : match [ 2 ] ?? `` ,
188188 date : {
189189 seconds : parseInt ( match [ 3 ] , 10 ) ,
190190 offset : ( parseInt ( match [ 4 ] , 10 ) / 100 ) * - 60 ,
191191 } ,
192- } as Person ;
192+ } ;
193193}
Original file line number Diff line number Diff line change @@ -86,7 +86,8 @@ export function encodeCommit(body: CommitBody) {
8686function formatPerson ( person : Person ) {
8787 return (
8888 safe ( person . name ) +
89- ' <' +
89+ ( safe ( person . name ) ? ' ' : '' ) +
90+ '<' +
9091 safe ( person . email ) +
9192 '> ' +
9293 formatDate ( person . date )
Original file line number Diff line number Diff line change 6969 ) ,
7070) ;
7171
72+ test (
73+ 'save and load commit with empty person name' ,
74+ testEncoding (
75+ {
76+ type : Type . commit ,
77+ body : {
78+ tree : 'df2b8fc99e1c1d4dbc0a854d9f72157f1d6ea078' ,
79+ parents : [ ] ,
80+ author : {
81+ name : '' ,
82+ email : 'me@mariusgundersen.net' ,
83+ date : {
84+ seconds : 1500840368 ,
85+ offset : - 2 * 60 ,
86+ } ,
87+ } ,
88+ committer : {
89+ name : 'Marius Gundersen' ,
90+ email : 'me@mariusgundersen.net' ,
91+ date : {
92+ seconds : 1500840368 ,
93+ offset : - 2 * 60 ,
94+ } ,
95+ } ,
96+ message : 'test\n' ,
97+ } ,
98+ } ,
99+ '92f15c00a43ca7bd64a94bcbee32a400f783351a' ,
100+ ) ,
101+ ) ;
102+
72103test (
73104 'save and load tag' ,
74105 testEncoding (
You can’t perform that action at this time.
0 commit comments