File tree 2 files changed +30
-5
lines changed
2 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -652,7 +652,12 @@ static struct digest {
652
652
* dp ++ = (REBUNI )n ;
653
653
up += 3 ;
654
654
len -= 2 ;
655
- } else {
655
+ }
656
+ else if (* up == space_char && as_uri ) {
657
+ * dp ++ = ' ' ;
658
+ up ++ ;
659
+ }
660
+ else {
656
661
* dp ++ = * up ++ ;
657
662
}
658
663
}
@@ -723,13 +728,13 @@ static struct digest {
723
728
* dp ++ = space_char ;
724
729
continue ;
725
730
}
726
- if (c == space_char ) goto escaped ;
731
+ if (c == space_char ) goto escaped_ascii ;
727
732
}
728
733
if (Check_Bit_Cased (VAL_SERIES (val_bitset ), c )) {
729
734
* dp ++ = c ;
730
735
continue ;
731
736
}
732
- escaped :
737
+ escaped_ascii :
733
738
* dp ++ = escape_char ;
734
739
* dp ++ = Hex_Digits [(c & 0xf0 ) >> 4 ];
735
740
* dp ++ = Hex_Digits [ c & 0xf ];
@@ -742,7 +747,16 @@ static struct digest {
742
747
while (up < ep ) {
743
748
REBUNI c = up [0 ];
744
749
up ++ ;
745
-
750
+ if (no_space ) {
751
+ if (c == ' ' ) {
752
+ * dp ++ = space_char ;
753
+ continue ;
754
+ }
755
+ if (c == space_char ) {
756
+ encoded_size = Encode_UTF8_Char (encoded , c );
757
+ goto escaped_uni ;
758
+ }
759
+ }
746
760
if (c >= 0x80 ) {// all non-ASCII characters *must* be percent encoded
747
761
encoded_size = Encode_UTF8_Char (encoded , c );
748
762
} else {
@@ -753,6 +767,7 @@ static struct digest {
753
767
encoded [0 ] = cast (REBYTE , c );
754
768
encoded_size = 1 ;
755
769
}
770
+ escaped_uni :
756
771
for (n = 0 ; n < encoded_size ; ++ n ) {
757
772
* dp ++ = escape_char ;
758
773
* dp ++ = Hex_Digits [(encoded [n ] & 0xf0 ) >> 4 ];
Original file line number Diff line number Diff line change @@ -1723,15 +1723,25 @@ Rebol [
1723
1723
--test-- "ENHEX/uri"
1724
1724
--assert "a%20b%2B" = enhex "a b+"
1725
1725
--assert "a+b%2B" = enhex/uri "a b+"
1726
+ --assert "a%20%C3%A1%2B" = enhex "a á+"
1727
+ --assert "a+%C3%A1%2B" = enhex/uri "a á+"
1726
1728
; quoted-printable:
1727
1729
--assert "a=20b_" = enhex/escape "a b_" #"="
1728
- --assert "a_b=5F" = enhex/uri/escape "a b_" #"="
1730
+ --assert "a_b=5F" = enhex/uri/escape "a b_" #"="
1731
+ --assert "a=20=C3=A1_" = enhex/escape "a á_" #"="
1732
+ --assert "a_=C3=A1=5F" = enhex/escape/uri "a á_" #"="
1733
+
1729
1734
--test-- "DEHEX/uri"
1730
1735
--assert "a+b+" = dehex "a+b%2B"
1731
1736
--assert "a b+" = dehex /uri "a+b%2B"
1732
1737
; quoted-printable:
1733
1738
--assert "a_b_" = dehex /escape"a_b=5F" #"="
1734
1739
--assert "a b_" = dehex /uri/escape"a_b=5F" #"="
1740
+ ; to get propper UTF8 results, we must use binary input (for now?)
1741
+ --assert "a á+" = to string! dehex to binary! "a%20%C3%A1%2B"
1742
+ --assert "a á+" = to string! dehex /uri to binary! "a+%C3%A1%2B"
1743
+ --assert "a á_" = to string! dehex /escape to binary! "a=20=C3=A1_" #"="
1744
+ --assert "a á_" = to string! dehex /escape/uri to binary! "a_=C3=A1=5F" #"="
1735
1745
1736
1746
===end-group===
1737
1747
You can’t perform that action at this time.
0 commit comments