mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: fix three tests with address errors (#9441)
This commit is contained in:
@ -18,7 +18,7 @@ const (
|
||||
// Example: assert base64.decode('ViBpbiBiYXNlIDY0') == 'V in base 64'
|
||||
pub fn decode(data string) []byte {
|
||||
size := data.len * 3 / 4
|
||||
if size <= 0 {
|
||||
if size <= 0 || data.len % 4 != 0 {
|
||||
return []
|
||||
}
|
||||
unsafe {
|
||||
@ -31,7 +31,7 @@ pub fn decode(data string) []byte {
|
||||
// decode_str is the string variant of decode
|
||||
pub fn decode_str(data string) string {
|
||||
size := data.len * 3 / 4
|
||||
if size <= 0 {
|
||||
if size <= 0 || data.len % 4 != 0 {
|
||||
return ''
|
||||
}
|
||||
unsafe {
|
||||
|
@ -43,9 +43,9 @@ fn test_decode() {
|
||||
assert base64.decode(man_pair.encoded) == man_pair.decoded.bytes()
|
||||
|
||||
// Test for incorrect padding.
|
||||
assert base64.decode('aGk') == 'hi'.bytes()
|
||||
assert base64.decode('aGk') == ''.bytes()
|
||||
assert base64.decode('aGk=') == 'hi'.bytes()
|
||||
assert base64.decode('aGk==') == 'hi'.bytes()
|
||||
assert base64.decode('aGk==') == ''.bytes()
|
||||
|
||||
for i, p in pairs {
|
||||
got := base64.decode(p.encoded)
|
||||
@ -60,9 +60,9 @@ fn test_decode_str() {
|
||||
assert base64.decode_str(man_pair.encoded) == man_pair.decoded
|
||||
|
||||
// Test for incorrect padding.
|
||||
assert base64.decode_str('aGk') == 'hi'
|
||||
assert base64.decode_str('aGk') == ''
|
||||
assert base64.decode_str('aGk=') == 'hi'
|
||||
assert base64.decode_str('aGk==') == 'hi'
|
||||
assert base64.decode_str('aGk==') == ''
|
||||
|
||||
for i, p in pairs {
|
||||
got := base64.decode_str(p.encoded)
|
||||
|
Reference in New Issue
Block a user