Last modified: 2008-03-13 19:55:19 UTC

Wikimedia Bugzilla is closed!

Wikimedia has migrated from Bugzilla to Phabricator. Bug reports should be created and updated in Wikimedia Phabricator instead. Please create an account in Phabricator and add your Bugzilla email address to it.
Wikimedia Bugzilla is read-only. If you try to edit or create any bug report in Bugzilla you will be shown an intentional error message.
In order to access the Phabricator task corresponding to a Bugzilla report, just remove "static-" from its URL.
You could still run searches in Bugzilla or access your list of votes but bug reports will obviously not be up-to-date in Bugzilla.
Bug 12120 - Unescaped quote in YAML output
Unescaped quote in YAML output
Product: MediaWiki
Classification: Unclassified
API (Other open bugs)
All All
: Normal normal with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
Depends on:
  Show dependency treegraph
Reported: 2007-11-26 14:42 UTC by Patrick Sinclair
Modified: 2008-03-13 19:55 UTC (History)
2 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Description Patrick Sinclair 2007-11-26 14:42:09 UTC
Quotes are not escaped properly in the YAML output, e.g.

This breaks the YAML parser in Ruby:

require 'yaml'
require 'open-uri'
p YAML::load( open('') )
Comment 1 Patrick Sinclair 2007-11-27 12:03:39 UTC
I have also encountered the following pages that are causing errors to the Ruby YAML parser:

In both cases this seems to be an error with the formatting of the categories YAML (one has a line break, one has a ':' in the title). 
Comment 2 Willemo 2008-01-09 11:49:12 UTC
I did take a look at this one, since I also figured out that titles containing ": " fails parsing in Ruby.

According to the YAML 1.0 specification ( " #" and ": " (also string starting with "!!", "[" and some others) are forbidden in so-called 'plain style' scalar syntax.

When I take a look at ApiFormatYaml_spyc.php, function _dumpNode only supports plain style:

 // It's mapped
 $string = $spaces.$key.': '.$value."\n";

This is a too simplistic approach to render YAML, in some situations.

To solve this, the _dumpNode function needs to be extended with a kind of YAML escape algorithm when plain style is not possible.
Comment 3 Roan Kattouw 2008-03-13 16:51:39 UTC
I've committed a fix in r31927 which (hopefully, don't have a YAML parser handy) fixes this issue. Requesting api.php?action=query&prop=info&titles=Main_Page|Talk:Main_Page now results in what I hope is correct YAML (those with YAML parsers, please test!). Note the difference between:

title: Main Page


title: |
        Talk:Main Page

The entire YAML output of the sample request is at the end of this message for completeness's sake. The criteria I used are:
* If the string contains newlines, use literal syntax (with the | character and all that) (was already present)
* If the string starts with : or # use literal syntax
* If the string starts with any of - ? , [ ] { } ! * & | > ' " % @ ` also use literal syntax
* In all other situations, use plain syntax (folded if the string is longer than 40 characters)


      from: Main_Page
      to: Main Page
      from: |
      to: |
        Talk:Main Page
      pageid: 54
      ns: 0
      title: Main Page
      touched: |
      lastrevid: 440
      counter: 86
      length: 76
      pageid: 12
      ns: 1
      title: |
        Talk:Main Page
      touched: |
      lastrevid: 448
      counter: 64
      length: 173

Comment 4 Roan Kattouw 2008-03-13 19:55:19 UTC
(In reply to comment #3)
> * If the string starts with : or # use literal syntax
That should be: "If the string *contains* : or #" (good catch, Loek)

Note You need to log in before you can comment on or make changes to this bug.