[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
|
||||
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
|
||||
result = YARP.parse("# -*- coding: utf-8 -*-\nident")
|
||||
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;
|
||||
while ((cursor = yp_memchr(cursor, 'c', (size_t) (cursor_limit - cursor), parser->encoding_changed, &parser->encoding)) != NULL) {
|
||||
if (
|
||||
(strncmp(cursor, "coding", key_length - 1) == 0) &&
|
||||
(cursor[key_length - 1] == ':' || cursor[key_length - 1] == '=')
|
||||
) {
|
||||
return cursor + key_length;
|
||||
if (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));
|
||||
size_t cur_pos = key_length + whitespace_after_coding;
|
||||
|
||||
if (cursor[cur_pos - 1] == ':' || cursor[cur_pos - 1] == '=') {
|
||||
return cursor + cur_pos;
|
||||
}
|
||||
}
|
||||
|
||||
cursor++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user