Fossil SCM
Allow backslash in card filenames without causing a SYNTAX error in card parsing.
Commit
0a242574208c2f370d28258f4fcea3700e279765
Parent
55a28e7f5aec16d…
1 file changed
+29
-34
+29
-34
| --- src/file.c | ||
| +++ src/file.c | ||
| @@ -483,58 +483,53 @@ | ||
| 483 | 483 | ** a file in a repository. Valid filenames follow all of the |
| 484 | 484 | ** following rules: |
| 485 | 485 | ** |
| 486 | 486 | ** * Does not begin with "/" |
| 487 | 487 | ** * Does not contain any path element named "." or ".." |
| 488 | -** * Does not contain any of these characters in the path: "\" | |
| 489 | 488 | ** * Does not end with "/". |
| 490 | 489 | ** * Does not contain two or more "/" characters in a row. |
| 491 | 490 | ** * Contains at least one character |
| 492 | 491 | ** |
| 493 | -** Invalid UTF8 characters result in a false return if bStrictUtf8 is | |
| 494 | -** true. If bStrictUtf8 is false, invalid UTF8 characters are silently | |
| 495 | -** ignored. | |
| 492 | +** Invalid UTF8 characters and "\". result in a false return if | |
| 493 | +** bStrictUtf8 is true. If bStrictUtf8 is false, invalid UTF8 | |
| 494 | +** characters and "\" are silently ignored. | |
| 496 | 495 | */ |
| 497 | 496 | int file_is_simple_pathname(const char *z, int bStrictUtf8){ |
| 498 | 497 | int i; |
| 499 | 498 | char c = z[0]; |
| 500 | - char maskNonAscii = bStrictUtf8 ? 0x80 : 0x00; | |
| 501 | 499 | if( c=='/' || c==0 ) return 0; |
| 502 | 500 | if( c=='.' ){ |
| 503 | 501 | if( z[1]=='/' || z[1]==0 ) return 0; |
| 504 | 502 | if( z[1]=='.' && (z[2]=='/' || z[2]==0) ) return 0; |
| 505 | 503 | } |
| 506 | 504 | for(i=0; (c=z[i])!=0; i++){ |
| 507 | - if( c & maskNonAscii ){ | |
| 508 | - if( (c & 0xf0) == 0xf0 ) { | |
| 509 | - /* Unicode characters > U+FFFF are not supported. | |
| 510 | - * Windows XP and earlier cannot handle them. | |
| 511 | - */ | |
| 512 | - return 0; | |
| 513 | - } | |
| 514 | - if( (c & 0xf0) == 0xe0 ) { | |
| 515 | - /* This is a 3-byte UTF-8 character */ | |
| 516 | - if ( (c & 0xfe) == 0xee ){ | |
| 517 | - /* Range U+E000 - U+FFFF (Starting with 0xee or 0xef in UTF-8 ) */ | |
| 518 | - if ( (c & 1) && ((z[i+1] & 0xff) >= 0xa4) ){ | |
| 519 | - /* But exclude U+F900 - U+FFFF (0xef followed by byte >= 0xa4), | |
| 520 | - * which contain valid characters. */ | |
| 521 | - continue; | |
| 522 | - } | |
| 523 | - /* Unicode character in the range U+E000 - U+F8FF are for | |
| 524 | - * private use, they shouldn't occur in filenames. */ | |
| 525 | - return 0; | |
| 526 | - } | |
| 527 | - if( ((c & 0xff) == 0xed) && ((z[i+1] & 0xe0) == 0xa0) ){ | |
| 528 | - /* Unicode character in the range U+D800 - U+DFFF are for | |
| 529 | - * surrogate pairs, they shouldn't occur in filenames. */ | |
| 530 | - return 0; | |
| 531 | - } | |
| 532 | - } | |
| 533 | - } | |
| 534 | - if( c=='\\' ){ | |
| 535 | - return 0; | |
| 505 | + if( bStrictUtf8 ){ | |
| 506 | + if( c & 0x80 ){ | |
| 507 | + if( (c & 0xf0) == 0xf0 ) { | |
| 508 | + /* Unicode characters > U+FFFF are not supported. | |
| 509 | + * Windows XP and earlier cannot handle them. | |
| 510 | + */ | |
| 511 | + return 0; | |
| 512 | + } | |
| 513 | + if( (c & 0xf0) == 0xe0 ) { | |
| 514 | + /* This is a 3-byte UTF-8 character */ | |
| 515 | + if ( (c & 0xfe) == 0xee ){ | |
| 516 | + /* Range U+E000 - U+FFFF (Starting with 0xee or 0xef in UTF-8 ) */ | |
| 517 | + if ( !(c & 1) || ((z[i+1] & 0xff) < 0xa4) ){ | |
| 518 | + /* Unicode character in the range U+E000 - U+F8FF are for | |
| 519 | + * private use, they shouldn't occur in filenames. */ | |
| 520 | + return 0; | |
| 521 | + } | |
| 522 | + } else if( ((c & 0xff) == 0xed) && ((z[i+1] & 0xe0) == 0xa0) ){ | |
| 523 | + /* Unicode character in the range U+D800 - U+DFFF are for | |
| 524 | + * surrogate pairs, they shouldn't occur in filenames. */ | |
| 525 | + return 0; | |
| 526 | + } | |
| 527 | + } | |
| 528 | + }else if( c=='\\' ){ | |
| 529 | + return 0; | |
| 530 | + } | |
| 536 | 531 | } |
| 537 | 532 | if( c=='/' ){ |
| 538 | 533 | if( z[i+1]=='/' ) return 0; |
| 539 | 534 | if( z[i+1]=='.' ){ |
| 540 | 535 | if( z[i+2]=='/' || z[i+2]==0 ) return 0; |
| 541 | 536 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -483,58 +483,53 @@ | |
| 483 | ** a file in a repository. Valid filenames follow all of the |
| 484 | ** following rules: |
| 485 | ** |
| 486 | ** * Does not begin with "/" |
| 487 | ** * Does not contain any path element named "." or ".." |
| 488 | ** * Does not contain any of these characters in the path: "\" |
| 489 | ** * Does not end with "/". |
| 490 | ** * Does not contain two or more "/" characters in a row. |
| 491 | ** * Contains at least one character |
| 492 | ** |
| 493 | ** Invalid UTF8 characters result in a false return if bStrictUtf8 is |
| 494 | ** true. If bStrictUtf8 is false, invalid UTF8 characters are silently |
| 495 | ** ignored. |
| 496 | */ |
| 497 | int file_is_simple_pathname(const char *z, int bStrictUtf8){ |
| 498 | int i; |
| 499 | char c = z[0]; |
| 500 | char maskNonAscii = bStrictUtf8 ? 0x80 : 0x00; |
| 501 | if( c=='/' || c==0 ) return 0; |
| 502 | if( c=='.' ){ |
| 503 | if( z[1]=='/' || z[1]==0 ) return 0; |
| 504 | if( z[1]=='.' && (z[2]=='/' || z[2]==0) ) return 0; |
| 505 | } |
| 506 | for(i=0; (c=z[i])!=0; i++){ |
| 507 | if( c & maskNonAscii ){ |
| 508 | if( (c & 0xf0) == 0xf0 ) { |
| 509 | /* Unicode characters > U+FFFF are not supported. |
| 510 | * Windows XP and earlier cannot handle them. |
| 511 | */ |
| 512 | return 0; |
| 513 | } |
| 514 | if( (c & 0xf0) == 0xe0 ) { |
| 515 | /* This is a 3-byte UTF-8 character */ |
| 516 | if ( (c & 0xfe) == 0xee ){ |
| 517 | /* Range U+E000 - U+FFFF (Starting with 0xee or 0xef in UTF-8 ) */ |
| 518 | if ( (c & 1) && ((z[i+1] & 0xff) >= 0xa4) ){ |
| 519 | /* But exclude U+F900 - U+FFFF (0xef followed by byte >= 0xa4), |
| 520 | * which contain valid characters. */ |
| 521 | continue; |
| 522 | } |
| 523 | /* Unicode character in the range U+E000 - U+F8FF are for |
| 524 | * private use, they shouldn't occur in filenames. */ |
| 525 | return 0; |
| 526 | } |
| 527 | if( ((c & 0xff) == 0xed) && ((z[i+1] & 0xe0) == 0xa0) ){ |
| 528 | /* Unicode character in the range U+D800 - U+DFFF are for |
| 529 | * surrogate pairs, they shouldn't occur in filenames. */ |
| 530 | return 0; |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | if( c=='\\' ){ |
| 535 | return 0; |
| 536 | } |
| 537 | if( c=='/' ){ |
| 538 | if( z[i+1]=='/' ) return 0; |
| 539 | if( z[i+1]=='.' ){ |
| 540 | if( z[i+2]=='/' || z[i+2]==0 ) return 0; |
| 541 |
| --- src/file.c | |
| +++ src/file.c | |
| @@ -483,58 +483,53 @@ | |
| 483 | ** a file in a repository. Valid filenames follow all of the |
| 484 | ** following rules: |
| 485 | ** |
| 486 | ** * Does not begin with "/" |
| 487 | ** * Does not contain any path element named "." or ".." |
| 488 | ** * Does not end with "/". |
| 489 | ** * Does not contain two or more "/" characters in a row. |
| 490 | ** * Contains at least one character |
| 491 | ** |
| 492 | ** Invalid UTF8 characters and "\". result in a false return if |
| 493 | ** bStrictUtf8 is true. If bStrictUtf8 is false, invalid UTF8 |
| 494 | ** characters and "\" are silently ignored. |
| 495 | */ |
| 496 | int file_is_simple_pathname(const char *z, int bStrictUtf8){ |
| 497 | int i; |
| 498 | char c = z[0]; |
| 499 | if( c=='/' || c==0 ) return 0; |
| 500 | if( c=='.' ){ |
| 501 | if( z[1]=='/' || z[1]==0 ) return 0; |
| 502 | if( z[1]=='.' && (z[2]=='/' || z[2]==0) ) return 0; |
| 503 | } |
| 504 | for(i=0; (c=z[i])!=0; i++){ |
| 505 | if( bStrictUtf8 ){ |
| 506 | if( c & 0x80 ){ |
| 507 | if( (c & 0xf0) == 0xf0 ) { |
| 508 | /* Unicode characters > U+FFFF are not supported. |
| 509 | * Windows XP and earlier cannot handle them. |
| 510 | */ |
| 511 | return 0; |
| 512 | } |
| 513 | if( (c & 0xf0) == 0xe0 ) { |
| 514 | /* This is a 3-byte UTF-8 character */ |
| 515 | if ( (c & 0xfe) == 0xee ){ |
| 516 | /* Range U+E000 - U+FFFF (Starting with 0xee or 0xef in UTF-8 ) */ |
| 517 | if ( !(c & 1) || ((z[i+1] & 0xff) < 0xa4) ){ |
| 518 | /* Unicode character in the range U+E000 - U+F8FF are for |
| 519 | * private use, they shouldn't occur in filenames. */ |
| 520 | return 0; |
| 521 | } |
| 522 | } else if( ((c & 0xff) == 0xed) && ((z[i+1] & 0xe0) == 0xa0) ){ |
| 523 | /* Unicode character in the range U+D800 - U+DFFF are for |
| 524 | * surrogate pairs, they shouldn't occur in filenames. */ |
| 525 | return 0; |
| 526 | } |
| 527 | } |
| 528 | }else if( c=='\\' ){ |
| 529 | return 0; |
| 530 | } |
| 531 | } |
| 532 | if( c=='/' ){ |
| 533 | if( z[i+1]=='/' ) return 0; |
| 534 | if( z[i+1]=='.' ){ |
| 535 | if( z[i+2]=='/' || z[i+2]==0 ) return 0; |
| 536 |