Re: What characters allowed in anchor names?

William Spitzak <[email protected]>
Newsgroups gmane.text.yaml.general
Message-ID <[email protected]>
Patch attached (note line numbers may not match as this is against my 
modified version)

Oren Ben-Kiki wrote:
> Yes, we relaxed it; libyaml needs to be fixed (in general it needs to be
> tweaked to become 1.2-compliant).
> 
> Have fun,
> 
>     Oren Ben-Kiki
> 
> On Wed, 2009-09-30 at 19:56 -0700, William Spitzak wrote:
>> According to the yaml 1.2 spec documentation, the characters allowed in 
>> an anchor name are all c-printable except space, tab, lf, cr, or one of 
>> ",[]{}". This seems to be true even in older versions.
>>
>> However the libyaml source I have is severely more restricted, to 
>> alphanumeric, dash, and underscore.

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf

_______________________________________________
Yaml-core mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/yaml-core
patch (text/plain, 2.4 KB)
diff --git a/yaml/src/emitter.c b/yaml/src/emitter.c
index 4eaee73..10203b2 100644
--- a/yaml/src/emitter.c
+++ b/yaml/src/emitter.c
@@ -1410,10 +1410,12 @@ yaml_emitter_analyze_anchor(yaml_emitter_t *emitter,
     }
 
     while (string.pointer != string.end) {
-        if (!IS_ALPHA(string)) {
+        if (IS_BLANKZ(string) || CHECK(string, ',')
+            || CHECK(string, '[') || CHECK(string, ']')
+            || CHECK(string, '{') || CHECK(string, '}')) {
             return yaml_emitter_set_emitter_error(emitter, alias ?
-                    "alias value must contain alphanumerical characters only" :
-                    "anchor value must contain alphanumerical characters only");
+                    "character not allowed in alias value" :
+                    "character not allowed in anchor value");
         }
         MOVE(string);
     }
diff --git a/yaml/src/scanner.c b/yaml/src/scanner.c
index f01e979..81ee7cc 100644
--- a/yaml/src/scanner.c
+++ b/yaml/src/scanner.c
@@ -2346,7 +2346,9 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token,
 
     if (!CACHE(parser, 1)) goto error;
 
-    while (IS_ALPHA(parser->buffer)) {
+    while (!IS_BLANKZ(parser->buffer) && !CHECK(parser->buffer, ',')
+           && !CHECK(parser->buffer, '[') && !CHECK(parser->buffer, ']')
+           && !CHECK(parser->buffer, '{') && !CHECK(parser->buffer, '}')) {
         if (!READ(parser, string)) goto error;
         if (!CACHE(parser, 1)) goto error;
         length ++;
@@ -2354,18 +2356,7 @@ yaml_parser_scan_anchor(yaml_parser_t *parser, yaml_token_t *token,
 
     end_mark = parser->mark;
 
-    /*
-     * Check if length of the anchor is greater than 0 and it is followed by
-     * a whitespace character or one of the indicators:
-     *
-     *      '?', ':', ',', ']', '}', '%', '@', '`'.
-     */
-
-    if (!length || !(IS_BLANKZ(parser->buffer) || CHECK(parser->buffer, '?')
-                || CHECK(parser->buffer, ':') || CHECK(parser->buffer, ',')
-                || CHECK(parser->buffer, ']') || CHECK(parser->buffer, '}')
-                || CHECK(parser->buffer, '%') || CHECK(parser->buffer, '@')
-                || CHECK(parser->buffer, '`'))) {
+    if (!length) {
         yaml_parser_set_scanner_error(parser, type == YAML_ANCHOR_TOKEN ?
                 "while scanning an anchor" : "while scanning an alias", start_mark,
                 "did not find expected alphabetic or numeric character");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.