-
Notifications
You must be signed in to change notification settings - Fork 683
Add new input validator API functions #1576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new input validator API functions #1576
Conversation
LGTM (informally). |
fbfedef
to
1503d7d
Compare
jerry-core/jerry.c
Outdated
@@ -256,6 +256,11 @@ jerry_parse (const jerry_char_t *source_p, /**< script source */ | |||
#ifdef JERRY_JS_PARSER | |||
jerry_assert_api_available (); | |||
|
|||
if (!lit_is_utf8_string_valid ((lit_utf8_byte_t *) source_p, (lit_utf8_size_t) source_size)) | |||
{ | |||
return ecma_raise_syntax_error (ECMA_ERR_MSG ("The input should be a valid UTF8 string.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Input must be a valid UTF-8 string.
jerry-core/jerry-snapshot.c
Outdated
{ | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? jerry_parse_and_save_snapshot calls jerry_parse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we do. It does not call jerry_parse
. It calls parser_parse_script
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is really not needed anymore.
1503d7d
to
ca54bf4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I have been thinking about this in the weekend. Perhaps we should make this a runtime enable.disable feature, and do check for all functions which accepts utf8/cesu8 input. This patch is more like a workaround than a fix. |
83b0356
to
3c1c77a
Compare
@zherczeg, @robertsipka I've updated the PR. Please review again. |
docs/02.API-REFERENCE.md
Outdated
- [jerry_get_utf8_string_size](#jerry_get_utf8_string_size) | ||
- [jerry_get_utf8_string_length](#jerry_get_utf8_string_length) | ||
- [jerry_is_utf8_string_valid](#jerry_is_utf8_string_valid) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need two newlines here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do. This is the style in the whole MD
docs/02.API-REFERENCE.md
Outdated
|
||
```c | ||
bool | ||
jerry_is_utf8_string_valid (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of jerry_is_valid_utf8_string? Somehow that is more natural to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to me. Should we rename the internal functions too? lit_is_valid_utf8_string
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we should. If you wish you can do it in this patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll do it in this patch.
jerry-core/jerry-snapshot.c
Outdated
{ | ||
return 0; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this is really not needed anymore.
|
||
**See also** | ||
|
||
- [jerry_run_simple](#jerry_run_simple) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jerry_run_simple expects utf8 string, not cesu8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, removed the reference from jerry_is_cesu8_string_valid
cae38f4
to
755a1e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after the rename.
jerry-core/jerry.c
Outdated
* false - otherwise | ||
*/ | ||
bool | ||
jerry_is_utf8_string_valid (const jerry_char_t *utf8_buf_p, /**< UTF-8 string */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this function as well (jerry_is_valid_utf8_string)
jerry-core/jerryscript.h
Outdated
@@ -330,6 +330,12 @@ bool jerry_foreach_object_property (const jerry_value_t obj_val, jerry_object_pr | |||
void *user_data_p); | |||
|
|||
/** | |||
* Input validatator functions | |||
*/ | |||
bool jerry_is_utf8_string_valid (const jerry_char_t *utf8_buf_p, jerry_size_t buf_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well.
docs/02.API-REFERENCE.md
Outdated
@@ -3287,6 +3309,99 @@ bool foreach_function (const jerry_value_t prop_name, | |||
- [jerry_object_property_foreach_t](#jerry_object_property_foreach_t) | |||
|
|||
|
|||
# Input validatator functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validator
jerry-core/jerryscript.h
Outdated
@@ -330,6 +330,12 @@ bool jerry_foreach_object_property (const jerry_value_t obj_val, jerry_object_pr | |||
void *user_data_p); | |||
|
|||
/** | |||
* Input validatator functions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validator
Fixes jerryscript-project#1549 JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]
755a1e8
to
70a562f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #1549
JerryScript-DCO-1.0-Signed-off-by: László Langó [email protected]