| CODENOTIFIER | HelpYou are not signed inSign in |
Project: Mongrel
Revision: 1031
Author: normalperson
Date: 14 Jul 2008 20:44:17
Changes:http_parser: restore r996 (accept '"', '<', and '>' characters in URLs)
This seems to have gotten accidentally dropped during a merge: r1020
Some broken web browsers don't properly escape ", <, and > characters
in URLs, however these URLs to occasionally legitimate and sometimes
show up.
This patch was submitted by Eden Li here:
http://rubyforge.org/pipermail/mongrel-users/2006-October/001845.html
This patch was accepted by Zed Shaw here:
http://rubyforge.org/pipermail/mongrel-users/2006-October/001847.html
| ... | ...@@ -504,13 +504,9 @@ | |
| 504 | 504 | switch( (*p) ) { |
| 505 | 505 | case 32: goto tr31; |
| 506 | case 35: goto st0; | |
| 506 | 507 | case 37: goto tr32; |
| 507 | case 60: goto st0; | |
| 508 | case 62: goto st0; | |
| 509 | 508 | case 127: goto st0; |
| 510 | 509 | } |
| 511 | if ( (*p) > 31 ) { | |
| 512 | if ( 34 <= (*p) && (*p) <= 35 ) | |
| 513 | goto st0; | |
| 514 | } else if ( (*p) >= 0 ) | |
| 510 | if ( 0 <= (*p) && (*p) <= 31 ) | |
| 515 | 511 | goto st0; |
| 516 | 512 | goto tr30; |
| ... | ...@@ -523,16 +519,12 @@ | |
| 523 | 519 | goto _test_eof21; |
| 524 | 520 | case 21: |
| 525 | #line 526 "http11_parser.c" | |
| 521 | #line 522 "http11_parser.c" | |
| 526 | 522 | switch( (*p) ) { |
| 527 | 523 | case 32: goto tr34; |
| 524 | case 35: goto st0; | |
| 528 | 525 | case 37: goto st22; |
| 529 | case 60: goto st0; | |
| 530 | case 62: goto st0; | |
| 531 | 526 | case 127: goto st0; |
| 532 | 527 | } |
| 533 | if ( (*p) > 31 ) { | |
| 534 | if ( 34 <= (*p) && (*p) <= 35 ) | |
| 535 | goto st0; | |
| 536 | } else if ( (*p) >= 0 ) | |
| 528 | if ( 0 <= (*p) && (*p) <= 31 ) | |
| 537 | 529 | goto st0; |
| 538 | 530 | goto st21; |
| ... | ...@@ -545,5 +537,5 @@ | |
| 545 | 537 | goto _test_eof22; |
| 546 | 538 | case 22: |
| 547 | #line 548 "http11_parser.c" | |
| 539 | #line 540 "http11_parser.c" | |
| 548 | 540 | if ( (*p) < 65 ) { |
| 549 | 541 | if ( 48 <= (*p) && (*p) <= 57 ) |
| ... | ...@@ -576,5 +568,5 @@ | |
| 576 | 568 | goto _test_eof24; |
| 577 | 569 | case 24: |
| 578 | #line 579 "http11_parser.c" | |
| 570 | #line 571 "http11_parser.c" | |
| 579 | 571 | switch( (*p) ) { |
| 580 | 572 | case 43: goto st24; |
| ... | ...@@ -601,12 +593,9 @@ | |
| 601 | 593 | goto _test_eof25; |
| 602 | 594 | case 25: |
| 603 | #line 604 "http11_parser.c" | |
| 595 | #line 596 "http11_parser.c" | |
| 604 | 596 | switch( (*p) ) { |
| 605 | 597 | case 32: goto tr8; |
| 606 | case 34: goto st0; | |
| 607 | 598 | case 35: goto tr9; |
| 608 | 599 | case 37: goto st26; |
| 609 | case 60: goto st0; | |
| 610 | case 62: goto st0; | |
| 611 | 600 | case 127: goto st0; |
| 612 | 601 | } |
| ... | ...@@ -648,13 +637,10 @@ | |
| 648 | 637 | goto _test_eof28; |
| 649 | 638 | case 28: |
| 650 | #line 651 "http11_parser.c" | |
| 639 | #line 640 "http11_parser.c" | |
| 651 | 640 | switch( (*p) ) { |
| 652 | 641 | case 32: goto tr42; |
| 653 | case 34: goto st0; | |
| 654 | 642 | case 35: goto tr43; |
| 655 | 643 | case 37: goto st29; |
| 656 | 644 | case 59: goto tr45; |
| 657 | case 60: goto st0; | |
| 658 | case 62: goto st0; | |
| 659 | 645 | case 63: goto tr46; |
| 660 | 646 | case 127: goto st0; |
| ... | ...@@ -700,12 +686,9 @@ | |
| 700 | 686 | goto _test_eof31; |
| 701 | 687 | case 31: |
| 702 | #line 703 "http11_parser.c" | |
| 688 | #line 689 "http11_parser.c" | |
| 703 | 689 | switch( (*p) ) { |
| 704 | 690 | case 32: goto tr8; |
| 705 | case 34: goto st0; | |
| 706 | 691 | case 35: goto tr9; |
| 707 | 692 | case 37: goto st32; |
| 708 | case 60: goto st0; | |
| 709 | case 62: goto st0; | |
| 710 | 693 | case 63: goto st34; |
| 711 | 694 | case 127: goto st0; |
| ... | ...@@ -751,12 +734,9 @@ | |
| 751 | 734 | goto _test_eof34; |
| 752 | 735 | case 34: |
| 753 | #line 754 "http11_parser.c" | |
| 736 | #line 737 "http11_parser.c" | |
| 754 | 737 | switch( (*p) ) { |
| 755 | 738 | case 32: goto tr53; |
| 756 | case 34: goto st0; | |
| 757 | 739 | case 35: goto tr54; |
| 758 | 740 | case 37: goto tr55; |
| 759 | case 60: goto st0; | |
| 760 | case 62: goto st0; | |
| 761 | 741 | case 127: goto st0; |
| 762 | 742 | } |
| ... | ...@@ -772,12 +752,9 @@ | |
| 772 | 752 | goto _test_eof35; |
| 773 | 753 | case 35: |
| 774 | #line 775 "http11_parser.c" | |
| 754 | #line 755 "http11_parser.c" | |
| 775 | 755 | switch( (*p) ) { |
| 776 | 756 | case 32: goto tr57; |
| 777 | case 34: goto st0; | |
| 778 | 757 | case 35: goto tr58; |
| 779 | 758 | case 37: goto st36; |
| 780 | case 60: goto st0; | |
| 781 | case 62: goto st0; | |
| 782 | 759 | case 127: goto st0; |
| 783 | 760 | } |
| ... | ...@@ -793,5 +770,5 @@ | |
| 793 | 770 | goto _test_eof36; |
| 794 | 771 | case 36: |
| 795 | #line 796 "http11_parser.c" | |
| 772 | #line 773 "http11_parser.c" | |
| 796 | 773 | if ( (*p) < 65 ) { |
| 797 | 774 | if ( 48 <= (*p) && (*p) <= 57 ) |
| ... | ...@@ -12,9 +12,10 @@ | |
| 12 | 12 | extra = ("!" | "*" | "'" | "(" | ")" | ","); |
| 13 | 13 | reserved = (";" | "/" | "?" | ":" | "@" | "&" | "=" | "+"); |
| 14 | unsafe = (CTL | " " | "\"" | "#" | "%" | "<" | ">"); | |
| 14 | sorta_safe = ("\"" | "<" | ">"); | |
| 15 | unsafe = (CTL | " " | "#" | "%" | sorta_safe); | |
| 15 | 16 | national = any -- (alpha | digit | reserved | extra | safe | unsafe); |
| 16 | 17 | unreserved = (alpha | digit | safe | extra | national); |
| 17 | 18 | escape = ("%" xdigit xdigit); |
| 18 | uchar = (unreserved | escape); | |
| 19 | uchar = (unreserved | escape | sorta_safe); | |
| 19 | 20 | pchar = (uchar | ":" | "@" | "&" | "=" | "+"); |
| 20 | 21 | tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t"); |
| ... | ...@@ -56,4 +56,22 @@ | |
| 56 | 56 | # assert !parser.error? |
| 57 | 57 | end |
| 58 | ||
| 59 | def test_parse_ie6_urls | |
| 60 | %w(/some/random/path" | |
| 61 | /some/random/path> | |
| 62 | /some/random/path< | |
| 63 | /we/love/you/ie6?q=<""> | |
| 64 | /url?<="&>=" | |
| 65 | /mal"formed"? | |
| 66 | ).each do |path| | |
| 67 | parser = HttpParser.new | |
| 68 | req = {} | |
| 69 | sorta_safe = %(GET #{path} HTTP/1.1\r\n\r\n) | |
| 70 | nread = parser.execute(req, sorta_safe, 0) | |
| 71 | assert_equal sorta_safe.length, nread | |
| 72 | assert parser.finished? | |
| 73 | assert !parser.error? | |
| 74 | end | |
| 75 | end | |
| 58 | 76 | |
| 59 | 77 | def test_parse_error |