iabudiab / HTMLKit

An Objective-C framework for your everyday HTML needs.
MIT License
239 stars 27 forks source link

Colons are stripped from attributes #30

Closed benny-innofaith closed 6 years ago

benny-innofaith commented 6 years ago

The problem manifest itself when reading a HTML file and outputting it again to a HTML string.

debug.html

<!DOCTYPE html>
    <head>
        <title>debug</title>
    </head>
    <body>
        <svg id="draw_area" width="600" height="800" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
            <image id="overlay_img" xlink:href="foo.png" x="0" y="0" width="600" height="800" />
        </svg>
    </body>
</html>
    NSString *dpath = [[NSBundle mainBundle] pathForResource:@"debug" ofType:@"html"];
    NSString *dcontent = [NSString stringWithContentsOfFile:dpath
                                   encoding:NSUTF8StringEncoding error:nil];

    HTMLDocument* ddocument = [HTMLDocument documentWithString:dcontent];
    dcontent = [[ddocument documentElement] innerHTML];

After above code the variable dcontent contains:

<head>
        <title>debug</title>
    </head>
    <body>
        <svg id="draw_area" width="600" height="800" xmlns="http://www.w3.org/2000/svg" xmlns xlink="http://www.w3.org/1999/xlink" version="1.1">
            <image id="overlay_img" xlink href="foo.png" x="0" y="0" width="600" height="800"></image>
        </svg>

</body>

Note how xmlns:xlink is converted to xmlns xlink and xlink:href to xlink href after outputting the content to HTML again. This broke the svg.

benny-innofaith commented 6 years ago

Can this code be released?

iabudiab commented 6 years ago

@benny-innofaith Done. Sorry for forgetting this. It just slipped my mind.