Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -585,6 +585,7 @@ |
586 | 586 | $prefixLengthTwo = substr( $urlPath, $inputOffset, 2 ); |
587 | 587 | $prefixLengthThree = substr( $urlPath, $inputOffset, 3 ); |
588 | 588 | $prefixLengthFour = substr( $urlPath, $inputOffset, 4 ); |
| 589 | + $trimOutput = false; |
589 | 590 | |
590 | 591 | if ( $prefixLengthTwo == './' ) { |
591 | 592 | # Step A, remove leading "./" |
— | — | @@ -604,12 +605,12 @@ |
605 | 606 | # remove last path component in output |
606 | 607 | $inputOffset += 2; |
607 | 608 | $urlPath[$inputOffset] = '/'; |
608 | | - $output = preg_replace('%(^|/)[^/]*$%', '', $output); |
| 609 | + $trimOutput = true; |
609 | 610 | } elseif ( $prefixLengthFour == '/../' ) { |
610 | 611 | # Step C, replace leading "/../" with "/" and |
611 | 612 | # remove last path component in output |
612 | 613 | $inputOffset += 3; |
613 | | - $output = preg_replace('%(^|/)[^/]*$%', '', $output); |
| 614 | + $trimOutput = true; |
614 | 615 | } elseif ( ( $prefixLengthOne == '.' ) && ( $inputOffset + 1 == $inputLength ) ) { |
615 | 616 | # Step D, remove "^.$" |
616 | 617 | $inputOffset += 1; |
— | — | @@ -618,10 +619,28 @@ |
619 | 620 | $inputOffset += 2; |
620 | 621 | } else { |
621 | 622 | # Step E, move leading path segment to output |
622 | | - preg_match( '%/?[^/]*%A', $urlPath, $matches, 0, $inputOffset ); |
623 | | - $inputOffset += strlen( $matches[0] ); |
624 | | - $output .= $matches[0]; |
| 623 | + if ( $prefixLengthOne == '/' ) { |
| 624 | + $slashPos = strpos( $urlPath, '/', $inputOffset + 1 ); |
| 625 | + } else { |
| 626 | + $slashPos = strpos( $urlPath, '/', $inputOffset ); |
| 627 | + } |
| 628 | + if ( $slashPos === false ) { |
| 629 | + $output .= substr( $urlPath, $inputOffset ); |
| 630 | + $inputOffset = $inputLength; |
| 631 | + } else { |
| 632 | + $output .= substr( $urlPath, $inputOffset, $slashPos - $inputOffset ); |
| 633 | + $inputOffset += $slashPos - $inputOffset; |
| 634 | + } |
625 | 635 | } |
| 636 | + |
| 637 | + if ( $trimOutput ) { |
| 638 | + $slashPos = strrpos( $output, '/' ); |
| 639 | + if ( $slashPos === false ) { |
| 640 | + $output = ''; |
| 641 | + } else { |
| 642 | + $output = substr( $output, 0, $slashPos ); |
| 643 | + } |
| 644 | + } |
626 | 645 | } |
627 | 646 | |
628 | 647 | return $output; |