mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-27 01:51:59 +00:00
Fix error in decodeURLComponent
This commit is contained in:
parent
f387e6013a
commit
eead7fcbac
@ -14,28 +14,33 @@ namespace ErrorCodes
|
||||
static size_t encodeURL(const char * __restrict src, size_t src_size, char * __restrict dst, bool space_as_plus)
|
||||
{
|
||||
char * dst_pos = dst;
|
||||
for (size_t i = 0; i < src_size; i++)
|
||||
for (size_t i = 0; i < src_size; ++i)
|
||||
{
|
||||
if ((src[i] >= '0' && src[i] <= '9') || (src[i] >= 'a' && src[i] <= 'z') || (src[i] >= 'A' && src[i] <= 'Z')
|
||||
|| src[i] == '-' || src[i] == '_' || src[i] == '.' || src[i] == '~')
|
||||
{
|
||||
*dst_pos++ = src[i];
|
||||
*dst_pos = src[i];
|
||||
++dst_pos;
|
||||
}
|
||||
else if (src[i] == ' ' && space_as_plus)
|
||||
{
|
||||
*dst_pos++ = '+';
|
||||
*dst_pos = '+';
|
||||
++dst_pos;
|
||||
}
|
||||
else
|
||||
{
|
||||
*dst_pos++ = '%';
|
||||
*dst_pos++ = hexDigitUppercase(src[i] >> 4);
|
||||
*dst_pos++ = hexDigitUppercase(src[i] & 0xf);
|
||||
dst_pos[0] = '%';
|
||||
++dst_pos;
|
||||
writeHexByteUppercase(src[i], dst_pos);
|
||||
dst_pos += 2;
|
||||
}
|
||||
}
|
||||
*dst_pos++ = src[src_size];
|
||||
*dst_pos = 0;
|
||||
++dst_pos;
|
||||
return dst_pos - dst;
|
||||
}
|
||||
|
||||
|
||||
/// We assume that size of the dst buf isn't less than src_size.
|
||||
static size_t decodeURL(const char * __restrict src, size_t src_size, char * __restrict dst, bool plus_as_space)
|
||||
{
|
||||
@ -120,10 +125,14 @@ struct CodeURLComponentImpl
|
||||
ColumnString::Chars & res_data, ColumnString::Offsets & res_offsets)
|
||||
{
|
||||
if (code_strategy == encode)
|
||||
//the destination(res_data) string is at most three times the length of the source string
|
||||
{
|
||||
/// the destination(res_data) string is at most three times the length of the source string
|
||||
res_data.resize(data.size() * 3);
|
||||
}
|
||||
else
|
||||
{
|
||||
res_data.resize(data.size());
|
||||
}
|
||||
|
||||
size_t size = offsets.size();
|
||||
res_offsets.resize(size);
|
||||
|
@ -0,0 +1,2 @@
|
||||
%D0%BA%D0%BB%D0%B8%D0%BA%D1%85%D0%B0%D1%83%D1%81 1
|
||||
1
|
5
tests/queries/0_stateless/02677_decode_url_component.sql
Normal file
5
tests/queries/0_stateless/02677_decode_url_component.sql
Normal file
@ -0,0 +1,5 @@
|
||||
SELECT
|
||||
encodeURLComponent('кликхаус') AS encoded,
|
||||
decodeURLComponent(encoded) = 'кликхаус' AS expected_EQ;
|
||||
|
||||
SELECT DISTINCT decodeURLComponent(encodeURLComponent(randomString(100) AS x)) = x FROM numbers(100000);
|
Loading…
Reference in New Issue
Block a user