Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changeset 1544

Show
Ignore:
Timestamp:
05/23/10 11:52:41 (15 years ago)
Author:
rsinfu
Message:

Fixed bugzilla 3200: std.xml doesn't follow spec for Tag.text.
Thanks to Rainer Schuetze for the patch!

Line 994: Here, we are decoding input, not encoding.
Line 1948: The text (pointed to by p) should be decoded.

In addition to the proposed patch, I explicitly specified DecodeMode?.LOOSE as done in other parts of this module. And I added Jesse Phillips' test case as a unittest.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/docsrc/changelog.dd

    r1533 r1544  
    44 
    55 
    66$(VERSION 047, May 9, 2010, =================================================, 
    77 
    88    $(WHATSNEW 
    99    $(LI std.functional: toDelegate now accepts callable(function pointers, delegates and objects implement opCall) ) 
    1010    $(LI std.traits: Added templates to get compile-time information about functions.) 
    1111    $(LI std.typecons: Added tie and AutoImplement.) 
    1212    ) 
    1313    $(BUGSFIXED 
     14    $(LI $(BUGZILLA 2835): std.socket.TcpSocket doesn't actually connect) 
     15    $(LI $(BUGZILLA 3200): std.xml doesn't follow spec for Tag.text) 
    1416    $(LI $(BUGZILLA 3873): std.range.repeat should have popBack defined) 
    1517    $(LI $(BUGZILLA 4202): Changset 1517 doesn't compile) 
    1618    ) 
    1719) 
    1820 
    1921<div id=version> 
    2022$(UL 
    2123    $(NEW 047) 
    2224    $(NEW 046) 
    2325    $(NEW 045) 
  • trunk/phobos/std/xml.d

    r1500 r1544  
    984984            if (optc(s,'/')) type = TagType.END; 
    985985            name = munch(s,"^/>"~whitespace); 
    986986            munch(s,whitespace); 
    987987            while(s.length > 0 && s[0] != '>' && s[0] != '/') 
    988988            { 
    989989                string key = munch(s,"^="~whitespace); 
    990990                munch(s,whitespace); 
    991991                reqc(s,'='); 
    992992                munch(s,whitespace); 
    993993                reqc(s,'"'); 
    994                 string val = encode(munch(s,"^\"")); 
     994                string val = decode(munch(s,"^\""), DecodeMode.LOOSE); 
    995995                reqc(s,'"'); 
    996996                munch(s,whitespace); 
    997997                attr[key] = val; 
    998998            } 
    999999            if (optc(s,'/')) 
    10001000            { 
    10011001                if (type == TagType.END) throw new TagException(""); 
    10021002                type = TagType.EMPTY; 
    10031003            } 
    10041004            reqc(s,'>'); 
     
    19381938                    } 
    19391939                } 
    19401940                else if (tag_.isEnd) 
    19411941                { 
    19421942                    auto startTag = startTags[tag_.name]; 
    19431943                    string text; 
    19441944 
    19451945                    immutable(char)* p = startTag.tagString.ptr 
    19461946                        + startTag.tagString.length; 
    19471947                    immutable(char)* q = tag_.tagString.ptr; 
    1948                     text = p[0..(q-p)]
     1948                    text = decode(p[0..(q-p)], DecodeMode.LOOSE)
    19491949 
    19501950                    auto element = new Element(startTag); 
    19511951                    if (text.length != 0) element ~= new Text(text); 
    19521952 
    19531953                    auto handler = tag_.name in onEndTag; 
    19541954                    if (handler !is null) (*handler)(element); 
    19551955                    else 
    19561956                    { 
    19571957                        handler = null in onEndTag; 
    19581958                        if (handler !is null) (*handler)(element); 
     
    26112611        ]"); 
    26122612    assert(false); 
    26132613    } 
    26142614    catch(CheckException e) 
    26152615    { 
    26162616        int n = e.toString().indexOf("end tag name \"genres\" differs" 
    26172617            " from start tag name \"genre\""); 
    26182618        assert(n != -1); 
    26192619    } 
    26202620  } 
     2621} 
     2622 
     2623unittest 
     2624{ 
     2625    string s = q"EOS 
     2626<?xml version="1.0" encoding="utf-8"?> <Tests> 
     2627    <Test thing="What &amp; Up">What &amp; Up Second</Test> 
     2628</Tests> 
     2629EOS"; 
     2630    auto xml = new DocumentParser(s); 
     2631 
     2632    xml.onStartTag["Test"] = (ElementParser xml) { 
     2633        assert(xml.tag.attr["thing"] == "What & Up"); 
     2634    }; 
     2635 
     2636    xml.onEndTag["Test"] = (in Element e) { 
     2637        assert(e.text == "What & Up Second"); 
     2638    }; 
     2639    xml.parse(); 
    26212640} 
    26222641 
    26232642/** The base class for exceptions thrown by this module */ 
    26242643class XMLException : Exception { this(string msg) { super(msg); } } 
    26252644 
    26262645// Other exceptions 
    26272646 
    26282647/// Thrown during Comment constructor 
    26292648class CommentException : XMLException 
    26302649{ private this(string msg) { super(msg); } }