Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/scanner.c
Original file line number Diff line number Diff line change
Expand Up @@ -2622,7 +2622,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
* The set of characters that may appear in URI is as follows:
*
* '0'-'9', 'A'-'Z', 'a'-'z', '_', '-', ';', '/', '?', ':', '@', '&',
* '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%'.
* '=', '+', '$', '.', '!', '~', '*', '\'', '(', ')', '%', '#'.
*
* If we are inside a verbatim tag <...> (parameter uri_char is true)
* then also the following flow indicators are allowed:
Expand All @@ -2638,6 +2638,7 @@ yaml_parser_scan_tag_uri(yaml_parser_t *parser, int uri_char, int directive,
|| CHECK(parser->buffer, '!') || CHECK(parser->buffer, '~')
|| CHECK(parser->buffer, '*') || CHECK(parser->buffer, '\'')
|| CHECK(parser->buffer, '(') || CHECK(parser->buffer, ')')
|| CHECK(parser->buffer, '#')
|| (uri_char && (
CHECK(parser->buffer, ',')
|| CHECK(parser->buffer, '[') || CHECK(parser->buffer, ']')
Expand Down
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ foreach(name IN ITEMS
run-scanner
test-nesting
test-reader
test-tag-uri
test-version
)
add_yaml_executable(${name})
Expand All @@ -26,4 +27,5 @@ endforeach()
add_test(NAME version COMMAND test-version)
add_test(NAME reader COMMAND test-reader)
add_test(NAME nesting COMMAND test-nesting)
add_test(NAME tag-uri COMMAND test-tag-uri)

4 changes: 2 additions & 2 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
AM_CPPFLAGS = -I$(top_srcdir)/include -Wall
#AM_CFLAGS = -Wno-pointer-sign
LDADD = $(top_builddir)/src/libyaml.la
TESTS = test-version test-reader test-nesting
check_PROGRAMS = test-version test-reader test-nesting
TESTS = test-version test-reader test-nesting test-tag-uri
check_PROGRAMS = test-version test-reader test-nesting test-tag-uri
noinst_PROGRAMS = run-scanner run-parser run-loader run-emitter run-dumper \
example-reformatter example-reformatter-alt \
example-deconstructor example-deconstructor-alt \
Expand Down
74 changes: 74 additions & 0 deletions tests/test-tag-uri.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include <yaml.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h>

static const struct {
const char *title;
const char *input;
const char *tag;
} cases[] = {
{"fragment in tag directive prefix",
"%TAG ! http://www.w3.org/2001/XMLSchema#\n---\n!foo bar\n",
"http://www.w3.org/2001/XMLSchema#foo"},
{"fragment in verbatim tag",
"!<http://example.com/#foo> bar\n",
"http://example.com/#foo"},
{"fragment in local tag",
"!foo#fragment bar\n",
"!foo#fragment"},
{"fragment in named handle suffix",
"%TAG !e! http://example.com/\n---\n!e!foo#fragment bar\n",
"http://example.com/foo#fragment"},
{"escaped fragment in verbatim tag",
"!<http://example.com/%23foo> bar\n",
"http://example.com/#foo"},
{"comments after directive and scalar",
"%TAG !e! http://example.com/ # comment\n"
"---\n!e!foo bar # comment\n",
"http://example.com/foo"},
{"comment after local tag",
"!foo # comment\nbar\n",
"!foo"}
};

int
main(void)
{
size_t i;
int failures = 0;

for (i = 0; i < sizeof(cases)/sizeof(cases[0]); i++) {
yaml_parser_t parser;
yaml_document_t document;
yaml_node_t *root;

assert(yaml_parser_initialize(&parser));
yaml_parser_set_input_string(&parser,
(const unsigned char *)cases[i].input, strlen(cases[i].input));

if (!yaml_parser_load(&parser, &document)) {
fprintf(stderr, "%s: %s\n", cases[i].title,
parser.problem ? parser.problem : "no error detail");
failures++;
}
else {
root = yaml_document_get_root_node(&document);
assert(root && root->type == YAML_SCALAR_NODE);
assert(strcmp((const char *)root->tag, cases[i].tag) == 0);
assert(root->data.scalar.length == 3);
assert(memcmp(root->data.scalar.value, "bar", 3) == 0);
yaml_document_delete(&document);
}

yaml_parser_delete(&parser);
}

return failures ? EXIT_FAILURE : EXIT_SUCCESS;
}