NSXMLDocument illegal serialization on 10.7

Originator:me
Number:rdar://10191354 Date Originated:2011-09-26
Status:Open Resolved:
Product:Mac OS X Product Version:10.7.2 (11C62)
Classification:Serious Bug Reproducible:Always
 
I've hit a serious issue with NSXMLDocument on 10.7.x. Attached is a simple test tool that reads a string, parses it with NSXMLDocument, then re-serializes it.

Compile with: clang -o passthrough -framework Foundation passthrough.m

Run as: ./passthrough basic.html

The serialization strips the close-quote from the html element, which is not good. Compiling the tool under 10.6 gives correct results.



--- basic.html	2011-09-26 23:12:39.000000000 -0700
+++ -	2011-09-26 23:27:10.000000000 -0700
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
+<html xmlns="http://www.w3.org/1999/xhtml>
     <head>



======== attachments

passthrough.m:

#import <Foundation/Foundation.h>

int main(int argc, const char *argv[])
{
    if (argc != 2)
        return -1;

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

    NSString *path = [NSString stringWithCString:argv[1] encoding:NSUTF8StringEncoding];
    NSString *xmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
    if (!xmlString)
        NSLog(@"couldn't read path %@", path);
    NSXMLDocument *doc = [[NSXMLDocument alloc] initWithXMLString:xmlString options:(NSXMLDocumentTidyHTML | NSXMLNodePreserveAll) error:nil];

    NSString *reserialized = [[NSString alloc] initWithData:[doc XMLDataWithOptions:(NSXMLDocumentTidyHTML | NSXMLNodePrettyPrint)] encoding:NSUTF8StringEncoding];
    puts([reserialized UTF8String]);

    [doc release];
    [reserialized release];
    [pool drain];
    return 0;
}




basic.html:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Library</title>
    </head>
    <body onload="initialize()">
        <div id="container"></div>
    </body>
</html>

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!