Skip to content
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

Escape flow indicators in shorthand tags #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/emitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ yaml_emitter_write_tag_handle(yaml_emitter_t *emitter,

static int
yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
yaml_char_t *value, size_t length, int need_whitespace);
yaml_char_t *value, size_t length,
int need_whitespace, int uri_char);

static int
yaml_emitter_write_plain_scalar(yaml_emitter_t *emitter,
Expand Down Expand Up @@ -628,7 +629,7 @@ yaml_emitter_emit_document_start(yaml_emitter_t *emitter,
strlen((char *)tag_directive->handle)))
return 0;
if (!yaml_emitter_write_tag_content(emitter, tag_directive->prefix,
strlen((char *)tag_directive->prefix), 1))
strlen((char *)tag_directive->prefix), 1, 1))
return 0;
if (!yaml_emitter_write_indent(emitter))
return 0;
Expand Down Expand Up @@ -1287,7 +1288,7 @@ yaml_emitter_process_tag(yaml_emitter_t *emitter)
return 0;
if (emitter->tag_data.suffix) {
if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix,
emitter->tag_data.suffix_length, 0))
emitter->tag_data.suffix_length, 0, 0))
return 0;
}
}
Expand All @@ -1296,7 +1297,7 @@ yaml_emitter_process_tag(yaml_emitter_t *emitter)
if (!yaml_emitter_write_indicator(emitter, "!<", 1, 0, 0))
return 0;
if (!yaml_emitter_write_tag_content(emitter, emitter->tag_data.suffix,
emitter->tag_data.suffix_length, 0))
emitter->tag_data.suffix_length, 0, 1))
return 0;
if (!yaml_emitter_write_indicator(emitter, ">", 0, 0, 0))
return 0;
Expand Down Expand Up @@ -1870,7 +1871,7 @@ yaml_emitter_write_tag_handle(yaml_emitter_t *emitter,
static int
yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
yaml_char_t *value, size_t length,
int need_whitespace)
int need_whitespace, int uri_char)
{
yaml_string_t string;
STRING_ASSIGN(string, value, length);
Expand All @@ -1885,12 +1886,14 @@ yaml_emitter_write_tag_content(yaml_emitter_t *emitter,
|| CHECK(string, '?') || CHECK(string, ':')
|| CHECK(string, '@') || CHECK(string, '&')
|| CHECK(string, '=') || CHECK(string, '+')
|| CHECK(string, '$') || CHECK(string, ',')
|| CHECK(string, '$') || CHECK(string, '\'')
|| CHECK(string, '_') || CHECK(string, '.')
|| CHECK(string, '~') || CHECK(string, '*')
|| CHECK(string, '\'') || CHECK(string, '(')
|| CHECK(string, ')') || CHECK(string, '[')
|| CHECK(string, ']')) {
|| CHECK(string, '(') || CHECK(string, ')')
|| (uri_char && (
CHECK(string, ',')
|| CHECK(string, '[') || CHECK(string, ']')
))) {
if (!WRITE(emitter, string)) return 0;
}
else {
Expand Down