[ruby/yarp] Allow whitespace after "(en)coding" before ":", as in "encoding :"
https://github.com/ruby/yarp/commit/d39a998182
This commit is contained in:
parent
7d32011399
commit
bf3d48e182
@ -50,6 +50,13 @@ class EncodingTest < Test::Unit::TestCase
|
|||||||
assert_equal Encoding.find("utf-8"), actual
|
assert_equal Encoding.find("utf-8"), actual
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_coding_with_whitespace
|
||||||
|
result = YARP.parse("# coding \t \r \v : \t \v \r ascii-8bit \nident")
|
||||||
|
actual = result.value.statements.body.first.name.encoding
|
||||||
|
assert_equal Encoding.find("ascii-8bit"), actual
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def test_emacs_style
|
def test_emacs_style
|
||||||
result = YARP.parse("# -*- coding: utf-8 -*-\nident")
|
result = YARP.parse("# -*- coding: utf-8 -*-\nident")
|
||||||
actual = result.value.statements.body.first.name.encoding
|
actual = result.value.statements.body.first.name.encoding
|
||||||
|
12
yarp/yarp.c
12
yarp/yarp.c
@ -4328,11 +4328,13 @@ parser_lex_encoding_comment_start(yp_parser_t *parser, const char *cursor, ptrdi
|
|||||||
|
|
||||||
const char *cursor_limit = cursor + length - key_length + 1;
|
const char *cursor_limit = cursor + length - key_length + 1;
|
||||||
while ((cursor = yp_memchr(cursor, 'c', (size_t) (cursor_limit - cursor), parser->encoding_changed, &parser->encoding)) != NULL) {
|
while ((cursor = yp_memchr(cursor, 'c', (size_t) (cursor_limit - cursor), parser->encoding_changed, &parser->encoding)) != NULL) {
|
||||||
if (
|
if (strncmp(cursor, "coding", key_length - 1) == 0) {
|
||||||
(strncmp(cursor, "coding", key_length - 1) == 0) &&
|
size_t whitespace_after_coding = yp_strspn_inline_whitespace(cursor + key_length - 1, parser->end - (cursor + key_length - 1));
|
||||||
(cursor[key_length - 1] == ':' || cursor[key_length - 1] == '=')
|
size_t cur_pos = key_length + whitespace_after_coding;
|
||||||
) {
|
|
||||||
return cursor + key_length;
|
if (cursor[cur_pos - 1] == ':' || cursor[cur_pos - 1] == '=') {
|
||||||
|
return cursor + cur_pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor++;
|
cursor++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user