mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
base64: use url encoding with updated api
Ensure that the URL alphabet for base64 is used with the urlencode functions (urlencode, urlencode_buffer, urlencode_temp and urlencode_new) are used. Add a new test.
This commit is contained in:
committed by
Christoffer Lerno
parent
8d03aafe72
commit
3f7f7a0aa7
@@ -31,7 +31,7 @@ fn void encode()
|
||||
char[64] buf;
|
||||
b.encode(tc.in, buf[:n])!;
|
||||
assert(buf[:n] == tc.out);
|
||||
assert(base64::encode_temp(tc.in) == tc.out);
|
||||
assert(base64::encode_temp(tc.in)! == tc.out);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -105,3 +105,34 @@ fn void decode_nopadding()
|
||||
assert(buf[:nn] == tc.out);
|
||||
}
|
||||
}
|
||||
|
||||
fn void! urlencode() {
|
||||
TestCase[] tcases = {
|
||||
{ x"14fb9c03d97e", "FPucA9l-"},
|
||||
};
|
||||
|
||||
@pool()
|
||||
{
|
||||
usz n;
|
||||
char[] got;
|
||||
char[64] buf;
|
||||
foreach (t : tcases)
|
||||
{
|
||||
Base64Encoder enc;
|
||||
enc.init(base64::URL_ALPHABET)!;
|
||||
n = enc.encode(t.in, buf[..])!;
|
||||
assert (buf[:n] == t.out, "got: %s, want: %s", (String)buf[:n], (String)t.out);
|
||||
|
||||
got = base64::urlencode_temp(t.in)!;
|
||||
assert (got == t.out, "got: %s, want: %s", got, (String)t.out);
|
||||
|
||||
Base64Decoder dec;
|
||||
dec.init(base64::URL_ALPHABET)!;
|
||||
n = dec.decode(t.out, buf[..])!;
|
||||
assert (buf[:n] == t.in, "got: %s, want: %s", (String)buf[:n], (String)t.in);
|
||||
|
||||
got = base64::urldecode_temp(t.out)!;
|
||||
assert (got == t.in, "got: %s, want: %s", got, (String)t.in);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user