File tree 2 files changed +32
-11
lines changed
2 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -973,15 +973,25 @@ static REBU64 base36_powers[BASE36_LENGTH] = {
973
973
}
974
974
975
975
if ((len % 3 ) != 0 ) {
976
- p [2 ] = p [3 ] = '=' ;
977
- * p ++ = table [src [x ] >> 2 ];
978
- if ((len - x ) >= 1 )
979
- * p ++ = table [((src [x ] & 0x3 ) << 4 ) + ((len - x ) == 1 ? 0 : src [x + 1 ] >> 4 )];
980
- else p ++ ;
981
- if ((len - x ) == 2 )
982
- * p ++ = table [(src [x + 1 ] & 0xF ) << 2 ];
983
- else p ++ ;
984
- p ++ ;
976
+ if (urlSafe ) {
977
+ // no padding
978
+ * p ++ = table [src [x ] >> 2 ];
979
+ if ((len - x ) >= 1 )
980
+ * p ++ = table [((src [x ] & 0x3 ) << 4 ) + ((len - x ) == 1 ? 0 : src [x + 1 ] >> 4 )];
981
+ if ((len - x ) == 2 )
982
+ * p ++ = table [(src [x + 1 ] & 0xF ) << 2 ];
983
+ }
984
+ else {
985
+ p [2 ] = p [3 ] = '=' ;
986
+ * p ++ = table [src [x ] >> 2 ];
987
+ if ((len - x ) >= 1 )
988
+ * p ++ = table [((src [x ] & 0x3 ) << 4 ) + ((len - x ) == 1 ? 0 : src [x + 1 ] >> 4 )];
989
+ else p ++ ;
990
+ if ((len - x ) == 2 )
991
+ * p ++ = table [(src [x + 1 ] & 0xF ) << 2 ];
992
+ else p ++ ;
993
+ p ++ ;
994
+ }
985
995
}
986
996
987
997
//if (*(p-1) != LF && x > 49 && brk) *p++ = LF; // adds LF before closing bracket
Original file line number Diff line number Diff line change @@ -107,14 +107,25 @@ AAACAAIAAAMDCCGTADs=}
107
107
} 64 ]
108
108
--test-- "debase 64 url 3"
109
109
key1: "qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA=="
110
+ key2: "qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA"
110
111
bin: try [debase /url key1 64 ]
111
- --assert true? all [binary? bin key1 = enbase /url bin 64 ]
112
+ --assert true? all [binary? bin key2 = enbase /url bin 64 ]
112
113
;debase is working also when input is missing the padding
113
- key2: "qL8R4QIcQ_ZsRqOAbeRfcZhilN_MksRtDaErMA"
114
114
--assert bin = try [debase /url key2 64 ]
115
115
116
116
===end-group===
117
117
118
+
119
+ ===start-group=== "enbase 64 - safe URL variant"
120
+ --test "enbase/url"
121
+ ;@@ https://github.com/Oldes/Rebol-issues/issues/2548
122
+ --assert "YQ==" == enbase "a" 64
123
+ --assert "YWE=" == enbase "aa" 64
124
+ --assert "YQ" == enbase /url "a" 64
125
+ --assert "YWE" == enbase /url "aa" 64
126
+ ===end-group===
127
+
128
+
118
129
===start-group=== "debase 16"
119
130
120
131
--test-- "debase 16 1"
You can’t perform that action at this time.
0 commit comments