Fix ecma_builtin_global_object_decode_uri_helper.
JerryScript-DCO-1.0-Signed-off-by: Ruben Ayrapetyan r.ayrapetyan@samsung.com
This commit is contained in:
@@ -857,7 +857,12 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
|
|||||||
|
|
||||||
lit_code_point_t decoded_byte;
|
lit_code_point_t decoded_byte;
|
||||||
|
|
||||||
lit_read_code_point_from_hex (input_char_p + 1, 2, &decoded_byte);
|
if (!lit_read_code_point_from_hex (input_char_p + 1, 2, &decoded_byte))
|
||||||
|
{
|
||||||
|
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
input_char_p += URI_ENCODED_BYTE_SIZE;
|
input_char_p += URI_ENCODED_BYTE_SIZE;
|
||||||
|
|
||||||
if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
if (decoded_byte <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
||||||
@@ -910,9 +915,9 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
lit_code_point_t cp;
|
lit_code_point_t cp;
|
||||||
lit_read_code_point_from_hex (input_char_p + 1, 2, &cp);
|
|
||||||
|
|
||||||
if ((cp & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER)
|
if (!lit_read_code_point_from_hex (input_char_p + 1, 2, &cp)
|
||||||
|
|| ((cp & LIT_UTF8_EXTRA_BYTE_MASK) != LIT_UTF8_EXTRA_BYTE_MARKER))
|
||||||
{
|
{
|
||||||
is_valid = false;
|
is_valid = false;
|
||||||
break;
|
break;
|
||||||
@@ -923,7 +928,8 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_valid)
|
if (!is_valid
|
||||||
|
|| !lit_is_utf8_string_valid (octets, bytes_count))
|
||||||
{
|
{
|
||||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
||||||
break;
|
break;
|
||||||
@@ -932,12 +938,8 @@ ecma_builtin_global_object_decode_uri_helper (ecma_value_t uri __attr_unused___,
|
|||||||
lit_code_point_t cp;
|
lit_code_point_t cp;
|
||||||
lit_read_code_point_from_utf8 (octets, bytes_count, &cp);
|
lit_read_code_point_from_utf8 (octets, bytes_count, &cp);
|
||||||
|
|
||||||
if ((bytes_count == 2 && cp <= LIT_UTF8_1_BYTE_CODE_POINT_MAX)
|
if (lit_is_code_point_utf16_high_surrogate (cp)
|
||||||
|| (bytes_count == 3 && cp <= LIT_UTF8_2_BYTE_CODE_POINT_MAX)
|
|| lit_is_code_point_utf16_low_surrogate (cp))
|
||||||
|| (bytes_count == 4 && cp <= LIT_UTF8_3_BYTE_CODE_POINT_MAX)
|
|
||||||
|| lit_is_code_unit_high_surrogate ((ecma_char_t) cp)
|
|
||||||
|| lit_is_code_unit_low_surrogate ((ecma_char_t) cp)
|
|
||||||
|| cp > LIT_UNICODE_CODE_POINT_MAX)
|
|
||||||
{
|
{
|
||||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
||||||
break;
|
break;
|
||||||
@@ -1067,7 +1069,7 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
|
|||||||
/* Input validation, we need to reject stray surrogates. */
|
/* Input validation, we need to reject stray surrogates. */
|
||||||
input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);
|
input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);
|
||||||
|
|
||||||
if (lit_is_code_unit_low_surrogate (ch))
|
if (lit_is_code_point_utf16_low_surrogate (ch))
|
||||||
{
|
{
|
||||||
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
ret_value = ecma_make_throw_obj_completion_value (ecma_new_standard_error (ECMA_ERROR_URI));
|
||||||
break;
|
break;
|
||||||
@@ -1075,7 +1077,7 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
|
|||||||
|
|
||||||
cp = ch;
|
cp = ch;
|
||||||
|
|
||||||
if (lit_is_code_unit_high_surrogate (ch))
|
if (lit_is_code_point_utf16_high_surrogate (ch))
|
||||||
{
|
{
|
||||||
if (input_char_p == input_end_p)
|
if (input_char_p == input_end_p)
|
||||||
{
|
{
|
||||||
@@ -1086,7 +1088,7 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
|
|||||||
ecma_char_t next_ch;
|
ecma_char_t next_ch;
|
||||||
lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);
|
lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);
|
||||||
|
|
||||||
if (lit_is_code_unit_low_surrogate (next_ch))
|
if (lit_is_code_point_utf16_low_surrogate (next_ch))
|
||||||
{
|
{
|
||||||
cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
|
cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
|
||||||
input_char_p += read_size;
|
input_char_p += read_size;
|
||||||
@@ -1132,12 +1134,12 @@ ecma_builtin_global_object_encode_uri_helper (ecma_value_t uri, /**< uri argumen
|
|||||||
input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);
|
input_char_p += lit_read_code_unit_from_utf8 (input_char_p, &ch);
|
||||||
cp = ch;
|
cp = ch;
|
||||||
|
|
||||||
if (lit_is_code_unit_high_surrogate (ch))
|
if (lit_is_code_point_utf16_high_surrogate (ch))
|
||||||
{
|
{
|
||||||
ecma_char_t next_ch;
|
ecma_char_t next_ch;
|
||||||
lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);
|
lit_utf8_size_t read_size = lit_read_code_unit_from_utf8 (input_char_p, &next_ch);
|
||||||
|
|
||||||
if (lit_is_code_unit_low_surrogate (next_ch))
|
if (lit_is_code_point_utf16_low_surrogate (next_ch))
|
||||||
{
|
{
|
||||||
cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
|
cp = lit_convert_surrogate_pair_to_code_point (ch, next_ch);
|
||||||
input_char_p += read_size;
|
input_char_p += read_size;
|
||||||
|
|||||||
@@ -223,26 +223,26 @@ lit_is_cesu8_string_valid (const lit_utf8_byte_t *utf8_buf_p, /**< utf-8 string
|
|||||||
} /* lit_is_cesu8_string_valid */
|
} /* lit_is_cesu8_string_valid */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the code unit type is low surrogate
|
* Check if the code point is UTF-16 low surrogate
|
||||||
*
|
*
|
||||||
* @return true / false
|
* @return true / false
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
lit_is_code_unit_low_surrogate (ecma_char_t code_unit) /**< code unit */
|
lit_is_code_point_utf16_low_surrogate (lit_code_point_t code_point) /**< code point */
|
||||||
{
|
{
|
||||||
return LIT_UTF16_LOW_SURROGATE_MIN <= code_unit && code_unit <= LIT_UTF16_LOW_SURROGATE_MAX;
|
return LIT_UTF16_LOW_SURROGATE_MIN <= code_point && code_point <= LIT_UTF16_LOW_SURROGATE_MAX;
|
||||||
} /* lit_is_code_unit_low_surrogate */
|
} /* lit_is_code_point_utf16_low_surrogate */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if the code unit type is high surrogate
|
* Check if the code point is UTF-16 high surrogate
|
||||||
*
|
*
|
||||||
* @return true / false
|
* @return true / false
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
lit_is_code_unit_high_surrogate (ecma_char_t code_unit) /**< code unit */
|
lit_is_code_point_utf16_high_surrogate (lit_code_point_t code_point) /**< code point */
|
||||||
{
|
{
|
||||||
return LIT_UTF16_HIGH_SURROGATE_MIN <= code_unit && code_unit <= LIT_UTF16_HIGH_SURROGATE_MAX;
|
return LIT_UTF16_HIGH_SURROGATE_MIN <= code_point && code_point <= LIT_UTF16_HIGH_SURROGATE_MAX;
|
||||||
} /* lit_is_code_unit_high_surrogate */
|
} /* lit_is_code_point_utf16_high_surrogate */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize iterator for traversing utf-8 string as a string of code units
|
* Initialize iterator for traversing utf-8 string as a string of code units
|
||||||
@@ -925,8 +925,8 @@ lit_code_point_t
|
|||||||
lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, /**< high surrogate code point */
|
lit_convert_surrogate_pair_to_code_point (ecma_char_t high_surrogate, /**< high surrogate code point */
|
||||||
ecma_char_t low_surrogate) /**< low surrogate code point */
|
ecma_char_t low_surrogate) /**< low surrogate code point */
|
||||||
{
|
{
|
||||||
JERRY_ASSERT (lit_is_code_unit_high_surrogate (high_surrogate));
|
JERRY_ASSERT (lit_is_code_point_utf16_high_surrogate (high_surrogate));
|
||||||
JERRY_ASSERT (lit_is_code_unit_low_surrogate (low_surrogate));
|
JERRY_ASSERT (lit_is_code_point_utf16_low_surrogate (low_surrogate));
|
||||||
|
|
||||||
lit_code_point_t code_point;
|
lit_code_point_t code_point;
|
||||||
code_point = (uint16_t) (high_surrogate - LIT_UTF16_HIGH_SURROGATE_MIN);
|
code_point = (uint16_t) (high_surrogate - LIT_UTF16_HIGH_SURROGATE_MIN);
|
||||||
|
|||||||
@@ -126,8 +126,8 @@ bool lit_is_utf8_string_valid (const lit_utf8_byte_t *, lit_utf8_size_t);
|
|||||||
bool lit_is_cesu8_string_valid (const lit_utf8_byte_t *, lit_utf8_size_t);
|
bool lit_is_cesu8_string_valid (const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||||
|
|
||||||
/* checks */
|
/* checks */
|
||||||
bool lit_is_code_unit_low_surrogate (ecma_char_t);
|
bool lit_is_code_point_utf16_low_surrogate (lit_code_point_t);
|
||||||
bool lit_is_code_unit_high_surrogate (ecma_char_t);
|
bool lit_is_code_point_utf16_high_surrogate (lit_code_point_t);
|
||||||
|
|
||||||
/* iteration */
|
/* iteration */
|
||||||
lit_utf8_iterator_t lit_utf8_iterator_create (const lit_utf8_byte_t *, lit_utf8_size_t);
|
lit_utf8_iterator_t lit_utf8_iterator_create (const lit_utf8_byte_t *, lit_utf8_size_t);
|
||||||
|
|||||||
@@ -475,8 +475,8 @@ lexer_transform_escape_sequences (const jerry_api_char_t *source_str_p, /**< str
|
|||||||
converted_char = next_char;
|
converted_char = next_char;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lit_is_code_unit_high_surrogate (prev_converted_char)
|
if (lit_is_code_point_utf16_high_surrogate (prev_converted_char)
|
||||||
&& lit_is_code_unit_low_surrogate (converted_char))
|
&& lit_is_code_point_utf16_low_surrogate (converted_char))
|
||||||
{
|
{
|
||||||
output_str_buf_iter_p -= LIT_UTF8_MAX_BYTES_IN_CODE_UNIT;
|
output_str_buf_iter_p -= LIT_UTF8_MAX_BYTES_IN_CODE_UNIT;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user