Permalink
Browse files

DocumentType.toString: Generate a valid <!DOCTYPE> string in all case…

…s where the DocumentType is valid. Won't include the internal subset (yet). Also, if the full DOCTYPE string is already known, just return it immediately without all the fuss of generating one.
  • Loading branch information...
1 parent 7c09501 commit ea434462d22dff130682ce3351b9b235ac7f4dff @djcsdy djcsdy committed Feb 8, 2011
Showing with 21 additions and 9 deletions.
  1. +21 −9 lib/jsdom/level2/core.js
View
@@ -481,16 +481,28 @@ core.DocumentType.prototype.__defineGetter__("internalSubset", function() {
});
core.DocumentType.prototype.toString = function() {
- var dt = '<!doctype ' + this.name;
- if (this.publicId && this.systemId) {
- dt += 'public ' + this.publicId + ' ' + this.systemId;
- dt = dt.toUpperCase();
+ if (this.ownerDocument._fullDT) {
+ return this.ownerDocument._fullDT;
+ }
+
+ var dt = '<!DOCTYPE ' + this.name;
+ if (this.publicId) {
+ // Public ID may never contain double quotes, so this is always safe.
+ dt += ' PUBLIC "' + this.publicId + '" ';
+ }
+ if (!this.publicId && this.systemId) {
+ dt += ' SYSTEM '
+ }
+ if (this.systemId) {
+ // System ID may contain double quotes OR single quotes, not never both.
+ if (this.systemId.indexOf('"') > -1) {
+ dt += "'" + this.systemId + "'";
+ } else {
+ dt += '"' + this.systemId + '"';
}
- dt += '>';
- if (this.ownerDocument._fullDT) {
- dt = this.ownerDocument._fullDT;
- }
- return dt;
+ }
+ dt += '>';
+ return dt;
};
core.Document.prototype.importNode = function(/* Node */ importedNode,

0 comments on commit ea43446

Please sign in to comment.