Permalink
Browse files

Modifications to properly handle rel/rev/property/about when they con…

…tain invalid CURIEs (by treating the attribute as if it's not present).

git-svn-id: http://rdfquery.googlecode.com/svn/trunk@170 70de001c-9c6e-11dd-979b-47109e308e52
  • Loading branch information...
1 parent 03b5d53 commit cc4542876884c909c6d6e31e37723e886d9d63b3 jeni.tennison committed Sep 10, 2009
Showing with 248 additions and 34 deletions.
  1. +51 −24 jquery.rdfa.js
  2. +16 −5 jquery.xmlns.js
  3. +22 −0 tests/jquery.rdf.js
  4. +145 −1 tests/jquery.rdfa.js
  5. +14 −4 tests/jquery.xmlns.js
View
75 jquery.rdfa.js
@@ -28,14 +28,20 @@
var
ns = {
rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
- xsd: "http://www.w3.org/2001/XMLSchema#"
+ xsd: "http://www.w3.org/2001/XMLSchema#",
+ xml: 'http://www.w3.org/XML/1998/namespace',
+ xmlns: 'http://www.w3.org/2000/xmlns/'
},
rdfXMLLiteral = ns.rdf + 'XMLLiteral',
rdfaCurieDefaults = $.fn.curie.defaults,
attRegex = /\s([^ =]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^ >]+))/g,
+
+ ncNameChar = '[-A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF\.0-9\u00B7\u0300-\u036F\u203F-\u2040]',
+ ncNameStartChar = '[\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]',
+ ncNameRegex = new RegExp('^' + ncNameStartChar + ncNameChar + '*$'),
docResource = $.rdf.resource('<>'),
@@ -83,20 +89,26 @@
getAttributes = function (elem) {
var i, e, a, tag, name, value, attMap, prefix,
- ns = {}, atts = {};
+ atts = {},
+ nsMap = {
+ xml: $.uri(ns.xml),
+ xmlns: $.uri(ns.xmlns)
+ };
e = elem[0];
- ns[':length'] = 0;
+ nsMap[':length'] = 2;
if (e.attributes && e.attributes.getNamedItemNS) {
attMap = e.attributes;
for (i = 0; i < attMap.length; i += 1) {
a = attMap[i];
if (/^xmlns(:(.+))?$/.test(a.nodeName) && a.nodeValue !== '') {
prefix = /^xmlns(:(.+))?$/.exec(a.nodeName)[2] || '';
- ns[prefix] = $.uri(a.nodeValue);
- ns[':length'] += 1;
- } else if (/rel|rev|lang|xml:lang/.test(a.nodeName)) {
- atts[a.nodeName] = a.nodeValue === '' ? undefined : a.nodeValue;
- } else if (/about|href|src|resource|property|typeof|content|datatype/.test(a.nodeName)) {
+ if (ncNameRegex.test(prefix) && prefix !== 'xml' && prefix !== 'xmlns' && a.nodeValue !== ns.xml && a.nodeValue !== ns.xmlns) {
+ nsMap[prefix] = $.uri(a.nodeValue);
+ nsMap[':length'] += 1;
+ }
+// } else if (/rel|rev|lang|xml:lang/.test(a.nodeName)) {
+// atts[a.nodeName] = a.nodeValue === '' ? undefined : a.nodeValue;
+ } else if (/rel|rev|lang|xml:lang|about|href|src|resource|property|typeof|content|datatype/.test(a.nodeName)) {
atts[a.nodeName] = a.nodeValue === null ? undefined : a.nodeValue;
}
}
@@ -108,32 +120,37 @@
value = a[2] || a[3] || a[4];
if (/^xmlns/.test(name) && name !== 'xmlns:' && value !== '') {
prefix = /^xmlns(:(.+))?$/.exec(name)[2] || '';
- ns[prefix] = $.uri(value);
- ns[':length'] += 1;
+ if (ncNameRegex.test(prefix) && prefix !== 'xml' && prefix !== 'xmlns' && a.nodeValue !== ns.xml && a.nodeValue !== ns.xmlns) {
+ nsMap[prefix] = $.uri(value);
+ nsMap[':length'] += 1;
+ }
} else if (/about|href|src|resource|property|typeof|content|datatype|rel|rev|lang|xml:lang/.test(name)) {
atts[name] = parseEntities(value);
}
a = attRegex.exec(tag);
}
attRegex.lastIndex = 0;
}
- return { atts: atts, namespaces: ns };
+ return { atts: atts, namespaces: nsMap };
},
getAttribute = function (elem, attr) {
var val = elem[0].getAttribute(attr);
- if (attr === 'rev' || attr === 'rel' || attr === 'lang' || attr === 'xml:lang') {
- val = val === '' ? undefined : val;
- }
+// if (attr === 'rev' || attr === 'rel' || attr === 'lang' || attr === 'xml:lang') {
+// val = val === '' ? undefined : val;
+// }
return val === null ? undefined : val;
},
resourceFromUri = function (uri) {
return $.rdf.resource(uri);
},
- resourceFromCurie = function (curie, elem, options) {
+ resourceFromCurie = function (curie, elem, noblanks, options) {
if (curie.substring(0, 2) === '_:') {
+ if (noblanks) {
+ return undefined;
+ }
return $.rdf.blank(curie);
} else {
try {
@@ -145,17 +162,17 @@
},
resourceFromSafeCurie = function (safeCurie, elem, options) {
- var m = /^\[([^\]]+)\]$/.exec(safeCurie),
+ var m = /^\[(.*)\]$/.exec(safeCurie),
base = options.base || elem.base();
- return m ? resourceFromCurie(m[1], elem, options) : resourceFromUri($.uri(safeCurie, base));
+ return m ? resourceFromCurie(m[1], elem, false, options) : resourceFromUri($.uri(safeCurie, base));
},
- resourcesFromCuries = function (curies, elem, options) {
+ resourcesFromCuries = function (curies, elem, noblanks, options) {
var i, resource, resources = [];
curies = curies && curies.split ? curies.split(/[ \t\n\r\x0C]+/g) : [];
for (i = 0; i < curies.length; i += 1) {
if (curies[i] !== '') {
- resource = resourceFromCurie(curies[i], elem, options);
+ resource = resourceFromCurie(curies[i], elem, noblanks, options);
if (resource !== undefined) {
resources.push(resource);
}
@@ -170,7 +187,7 @@
curies = curies && curies.split ? curies.split(/\s+/) : [];
for (i = 0; i < curies.length; i += 1) {
if (curies[i] !== '') {
- r = resourceFromCurie(curies[i], null, options);
+ r = resourceFromCurie(curies[i], null, false, options);
if (r !== resource) {
newCuries.push(curies[i]);
}
@@ -337,6 +354,19 @@
}
}
context.curieOptions = $.extend({}, rdfaCurieDefaults, { namespaces: namespaces, base: this.base() });
+ rels = resourcesFromCuries(atts.rel, this, true, context.curieOptions);
+ revs = resourcesFromCuries(atts.rev, this, true, context.curieOptions);
+ properties = resourcesFromCuries(atts.property, this, true, context.curieOptions);
+ // If all the CURIEs are invalid, act as if the rel/rev never existed
+ if (atts.rel && atts.rel.length > 0 && rels.length === 0) {
+ atts.rel = undefined;
+ }
+ if (atts.rev && atts.rev.length > 0 && revs.length === 0) {
+ atts.rev = undefined;
+ }
+ if (atts.property && atts.property.length > 0 && properties.length === 0) {
+ atts.property = undefined;
+ }
subject = getSubject(this, context);
lang = getLang(this, context);
if (subject.skip) {
@@ -358,12 +388,11 @@
}
}
resource = getObjectResource(this, context);
- types = resourcesFromCuries(atts['typeof'], this, context.curieOptions);
+ types = resourcesFromCuries(atts['typeof'], this, false, context.curieOptions);
for (i = 0; i < types.length; i += 1) {
triple = $.rdf.triple(subject, $.rdf.type, types[i], { source: this[0] });
triples.push(triple);
}
- properties = resourcesFromCuries(atts.property, this, context.curieOptions);
if (properties.length > 0) {
datatype = atts.datatype;
content = atts.content;
@@ -398,8 +427,6 @@
triples.push(triple);
}
}
- rels = resourcesFromCuries(atts.rel, this, context.curieOptions);
- revs = resourcesFromCuries(atts.rev, this, context.curieOptions);
if (atts.resource !== undefined || atts.href !== undefined) {
// make the triples immediately
if (rels !== undefined) {
View
21 jquery.xmlns.js
@@ -20,7 +20,15 @@
(function ($) {
var
- xmlnsRegex = /\sxmlns(?::([^ =]+))?\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
+ xmlNs = 'http://www.w3.org/XML/1998/namespace',
+ xmlnsNs = 'http://www.w3.org/2000/xmlns/',
+
+ xmlnsRegex = /\sxmlns(?::([^ =]+))?\s*=\s*(?:"([^"]*)"|'([^']*)')/g,
+
+ ncNameChar = '[-A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF\.0-9\u00B7\u0300-\u036F\u203F-\u2040]',
+ ncNameStartChar = '[\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF\u0100-\u0131\u0134-\u013E\u0141-\u0148\u014A-\u017E\u0180-\u01C3\u01CD-\u01F0\u01F4-\u01F5\u01FA-\u0217\u0250-\u02A8\u02BB-\u02C1\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03CE\u03D0-\u03D6\u03DA\u03DC\u03DE\u03E0\u03E2-\u03F3\u0401-\u040C\u040E-\u044F\u0451-\u045C\u045E-\u0481\u0490-\u04C4\u04C7-\u04C8\u04CB-\u04CC\u04D0-\u04EB\u04EE-\u04F5\u04F8-\u04F9\u0531-\u0556\u0559\u0561-\u0586\u05D0-\u05EA\u05F0-\u05F2\u0621-\u063A\u0641-\u064A\u0671-\u06B7\u06BA-\u06BE\u06C0-\u06CE\u06D0-\u06D3\u06D5\u06E5-\u06E6\u0905-\u0939\u093D\u0958-\u0961\u0985-\u098C\u098F-\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09DC-\u09DD\u09DF-\u09E1\u09F0-\u09F1\u0A05-\u0A0A\u0A0F-\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32-\u0A33\u0A35-\u0A36\u0A38-\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8B\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2-\u0AB3\u0AB5-\u0AB9\u0ABD\u0AE0\u0B05-\u0B0C\u0B0F-\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32-\u0B33\u0B36-\u0B39\u0B3D\u0B5C-\u0B5D\u0B5F-\u0B61\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99-\u0B9A\u0B9C\u0B9E-\u0B9F\u0BA3-\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB5\u0BB7-\u0BB9\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C33\u0C35-\u0C39\u0C60-\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CDE\u0CE0-\u0CE1\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D28\u0D2A-\u0D39\u0D60-\u0D61\u0E01-\u0E2E\u0E30\u0E32-\u0E33\u0E40-\u0E45\u0E81-\u0E82\u0E84\u0E87-\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA-\u0EAB\u0EAD-\u0EAE\u0EB0\u0EB2-\u0EB3\u0EBD\u0EC0-\u0EC4\u0F40-\u0F47\u0F49-\u0F69\u10A0-\u10C5\u10D0-\u10F6\u1100\u1102-\u1103\u1105-\u1107\u1109\u110B-\u110C\u110E-\u1112\u113C\u113E\u1140\u114C\u114E\u1150\u1154-\u1155\u1159\u115F-\u1161\u1163\u1165\u1167\u1169\u116D-\u116E\u1172-\u1173\u1175\u119E\u11A8\u11AB\u11AE-\u11AF\u11B7-\u11B8\u11BA\u11BC-\u11C2\u11EB\u11F0\u11F9\u1E00-\u1E9B\u1EA0-\u1EF9\u1F00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2126\u212A-\u212B\u212E\u2180-\u2182\u3041-\u3094\u30A1-\u30FA\u3105-\u312C\uAC00-\uD7A3\u4E00-\u9FA5\u3007\u3021-\u3029_]',
+ ncNameRegex = new RegExp('^' + ncNameStartChar + ncNameChar + '*$');
+
/**
* Returns the namespaces declared in the scope of the first selected element, or
@@ -58,14 +66,17 @@
if (uri === undefined) {
if (prefix === undefined) { // get the in-scope declarations on the first element
if (ns === undefined) {
- ns = {};
+ ns = {
+ xml: $.uri(xmlNs),
+ xmlns: $.uri(xmlnsNs)
+ };
if (e.attributes && e.attributes.getNamedItemNS) {
for (i = 0; i < e.attributes.length; i += 1) {
a = e.attributes[i];
if (/^xmlns(:(.+))?$/.test(a.nodeName)) {
prefix = /^xmlns(:(.+))?$/.exec(a.nodeName)[2] || '';
value = a.nodeValue;
- if (prefix === '' || value !== '') {
+ if (prefix === '' || (value !== '' && value !== xmlNs && value !== xmlnsNs && ncNameRegex.test(prefix) && prefix !== 'xml' && prefix !== 'xmlns')) {
ns[prefix] = $.uri(a.nodeValue);
found = true;
}
@@ -77,7 +88,7 @@
while (a !== null) {
prefix = a[1] || '';
value = a[2] || a[3];
- if (prefix === '' || value !== '') {
+ if (prefix === '' || (value !== '' && value !== xmlNs && value !== xmlnsNs && ncNameRegex.test(prefix) && prefix !== 'xml' && prefix !== 'xmlns')) {
ns[prefix] = $.uri(a[2] || a[3]);
found = true;
}
@@ -92,7 +103,7 @@
return ns;
} else if (typeof prefix === 'object') { // set the prefix mappings defined in the object
for (p in prefix) {
- if (typeof prefix[p] === 'string') {
+ if (typeof prefix[p] === 'string' && ncNameRegex.test(p)) {
this.xmlns(p, prefix[p]);
}
}
View
22 tests/jquery.rdf.js
@@ -1277,6 +1277,28 @@ test("loading RDF/XML with xml:lang attributes in it", function () {
equals(triples[2].object.lang, 'en');
});
+test("loading RDF/XML with xml:lang attributes on property elements", function () {
+ var xml =
+ '<rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' +
+ ' xmlns:dc="http://purl.org/dc/elements/1.1/"' +
+ ' rdf:about="http://example.org/buecher/baum">' +
+ ' <dc:title xml:lang="de">Der Baum</dc:title>' +
+ ' <dc:description xml:lang="de">Das Buch ist außergewöhnlich</dc:description>' +
+ ' <dc:title xml:lang="en">The Tree</dc:title>' +
+ '</rdf:Description>';
+ var doc = parseFromString(xml);
+ var databank = $.rdf.databank();
+ databank.load(doc);
+ equals(databank.size(), 3);
+ var triples = databank.triples();
+ equals(triples[0].object.value, 'Der Baum');
+ equals(triples[0].object.lang, 'de');
+ equals(triples[1].object.value, 'Das Buch ist außergewöhnlich');
+ equals(triples[1].object.lang, 'de');
+ equals(triples[2].object.value, 'The Tree');
+ equals(triples[2].object.lang, 'en');
+});
+
test("loading RDF/XML containing XML literals", function () {
var xml =
'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' +
View
146 tests/jquery.rdfa.js
@@ -12,7 +12,9 @@ var ns = { namespaces: {
ex: "http://example.org/",
sioc: "http://rdfs.org/sioc/ns#",
xhv: "http://www.w3.org/1999/xhtml/vocab#",
- prism: "http://prism.talis.com/schema#"
+ prism: "http://prism.talis.com/schema#",
+ xml: 'http://www.w3.org/XML/1998/namespace',
+ xmlns: 'http://www.w3.org/2000/xmlns/'
}};
function setup(rdfa) {
@@ -182,6 +184,124 @@ test("Empty xmlns value", function () {
$('#main > p').remove();
});
+test("Non-NCName prefix", function () {
+ setup('<p xmlns:0="http://example.org/" property="0:test">Test</p>');
+ testTriples($('#main > p').rdf(), []);
+ $('#main > p').remove();
+});
+
+test("Underscore prefix", function () {
+ setup('<p xmlns:_="http://example.org/" property="_:test">Test</p>');
+ testTriples($('#main > p').rdf(), []);
+ $('#main > p').remove();
+});
+
+test("xml prefix with wrong namespace", function () {
+ setup('<p xmlns:xml="http://example.org/" property="xml:test">Test</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<> xml:test "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
+test("xmlns declaration", function () {
+ setup('<p xmlns:xmlns="http://www.w3.org/2000/xmlns/" property="xmlns:test">Test</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<> xmlns:test "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
+test("xmlns declaration with wrong namespace", function () {
+ setup('<p xmlns:xmlns="http://example.org/" property="xmlns:test">Test</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<> xmlns:test "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
+test("bad namespace declaration (xml namespace)", function () {
+ setup('<p xmlns:ex2="http://www.w3.org/XML/1998/namespace" property="ex2:test">Test</p>');
+ testTriples($('#main > p').rdf(), []);
+ $('#main > p').remove();
+});
+
+test("bad namespace declaration (xmlns namespace)", function () {
+ setup('<p xmlns:ex2="http://www.w3.org/2000/xmlns/" property="ex2:test">Test</p>');
+ testTriples($('#main > p').rdf(), []);
+ $('#main > p').remove();
+});
+
+test("ignoring about with invalid prefix", function () {
+ setup('<p xmlns:ex="http://example.org/" xmlns:0="http://example.org/error/">' +
+ '<span src="http://example.com/">' +
+ ' <span property="ex:test1">Test</span>' +
+ '</span>' +
+ '<span about="[0:bogus]" src="http://example.com/">' +
+ ' <span property="ex:test">Test</span>' +
+ '</span>' +
+ '</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<http://example.com/> <http://example.org/test1> "Test" .'),
+ $.rdf.triple('<http://example.com/> <http://example.org/test> "Test" .')
+ ]);
+ $('#main > p').remove();
+});
+
+test("ignore rel attribute that contains invalid CURIEs", function () {
+ setup('<p xmlns:ex="http://example.org/" xmlns:0="http://example.org/error/">' +
+ '<span property="ex:test1" href="http://example.org/href">Test</span>' +
+ '<span rel="ex:test2" property="ex:test3" href="http://example.org/href">Test</span>' +
+ '<span rel="0:test4" property="ex:test5" href="http://example.org/href">Test</span>' +
+ '</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<http://example.org/href> <http://example.org/test1> "Test" .'),
+ $.rdf.triple('<> <http://example.org/test3> "Test" .'),
+ $.rdf.triple('<> <http://example.org/test2> <http://example.org/href> .'),
+ $.rdf.triple('<http://example.org/href> <http://example.org/test5> "Test" .')
+ ]);
+ $('#main > p').remove();
+});
+
+test("count rel attribute that is empty", function () {
+ setup('<p xmlns:ex="http://example.org/">' +
+ '<span property="ex:test1" href="http://example.org/href">Test</span>' +
+ '<span rel="ex:test2" property="ex:test3" href="http://example.org/href">Test</span>' +
+ '<span rel="" property="ex:test5" href="http://example.org/href">Test</span>' +
+ '</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<http://example.org/href> <http://example.org/test1> "Test" .'),
+ $.rdf.triple('<> <http://example.org/test3> "Test" .'),
+ $.rdf.triple('<> <http://example.org/test2> <http://example.org/href> .'),
+ $.rdf.triple('<> <http://example.org/test5> "Test" .')
+ ]);
+ $('#main > p').remove();
+});
+
+test("ignore property attribute that contains invalid CURIEs", function () {
+ setup('<div>' +
+ '<p xmlns:ex="http://example.org/" about="http://example.com/" rel="ex:rel1">' +
+ ' <span content="Content 1"><span about="http://example.net/">Test 1</span>' +
+ '</p>' +
+ '<p xmlns:ex="http://example.org/" about="http://example.com/" rel="ex:rel2">' +
+ ' <span property="ex:prop" content="Content 2"><span about="http://example.net/">Test 2</span></span>' +
+ '</p>' +
+ '<p xmlns:ex="http://example.org/" about="http://example.com/" rel="ex:rel3">' +
+ ' <span property="bogus:bogus" content="Content 3"><span about="http://example.net/">Test 3</span></span>' +
+ '</p>' +
+ '</div>');
+ var data = $('#main > div').rdf().databank.triples();
+ equals(data[0].toString(), $.rdf.triple('<http://example.com/> <http://example.org/rel1> <http://example.net/> .').toString());
+ equals(data[1].subject.value, 'http://example.com/');
+ equals(data[1].property.value, 'http://example.org/rel2');
+ equals(data[1].object.type, 'bnode');
+ equals(data[2].subject.type, 'bnode');
+ equals(data[2].property.value, 'http://example.org/prop');
+ equals(data[2].object.value, 'Content 2');
+ equals(data[3].toString(), $.rdf.triple('<http://example.com/> <http://example.org/rel3> <http://example.net/> .').toString())
+ $('#main > p').remove();
+});
+
test("Digit in curie", function () {
setup('<p xmlns:ex="http://example.org/" property="ex:one2three4">Test</p>');
testTriples($('#main > p').rdf(), [
@@ -191,6 +311,30 @@ test("Digit in curie", function () {
$('#main > p').remove();
});
+test("Square brackets in CURIE", function () {
+ setup('<p xmlns:ex="http://example.org/1/" xmlns:[ex="http://example.org/2/" about="[[ex:test]]" property="ex:test">Test</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<> <http://example.org/1/test> "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
+test("ignore about attribute that contains invalid CURIE", function () {
+ setup('<p about="http://example.net/" xmlns:ex="http://example.org/1/" xmlns:[ex="http://example.org/2/"><span about="[[ex:test]]" property="ex:test">Test</span></p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<http://example.net/> <http://example.org/1/test> "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
+test("ignore about attribute that contains invalid CURIE when setting subject", function () {
+ setup('<p xmlns:ex="http://example.org/1/" xmlns:[ex="http://example.org/2/" about="[[ex:test]]" resource="http://example.net/" property="ex:test">Test</p>');
+ testTriples($('#main > p').rdf(), [
+ $.rdf.triple('<http://example.net/> <http://example.org/1/test> "Test" .', ns)
+ ]);
+ $('#main > p').remove();
+});
+
test("With both lang and xml:lang defined", function () {
setup('<p xmlns:ex="http://example.org/" property="ex:test" lang="aa" xml:lang="bb">Test</p>');
testTriples($('#main > p').rdf(), [
View
18 tests/jquery.xmlns.js
@@ -13,7 +13,9 @@ var ns = {
xhv: "http://www.w3.org/1999/xhtml/vocab#",
prism: "http://prism.talis.com/schema#",
xsd: "http://www.w3.org/2001/XMLSchema#",
- rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ rdf: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
+ xml: 'http://www.w3.org/XML/1998/namespace',
+ xmlns: 'http://www.w3.org/2000/xmlns/'
}
module("When getting all namespaces");
@@ -29,7 +31,7 @@ test("on an element with three namespaces declared on it, including an empty one
equals(namespaces.sioc, ns.sioc);
for (n in namespaces) {
- if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd' ) {
+ if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd' && n !== 'xml' && n !== 'xmlns') {
ok(false, 'unexpected namespace: ' + n + '=' + namespaces[n]);
}
}
@@ -41,7 +43,7 @@ test("on an element that inherits namespaces", function() {
equals(namespaces.foaf, ns.foaf);
equals(namespaces[''], ns.html);
for (n in namespaces) {
- if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd') {
+ if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd' && n !== 'xml' && n !== 'xmlns') {
ok(false, 'unexpected namespace: ' + n + '=' + namespaces[n]);
}
}
@@ -55,7 +57,7 @@ test("on a sequence of two elements", function() {
equals(namespaces.foaf, 'http://www.example.org/foaf');
equals(namespaces[''], ns.html);
for (n in namespaces) {
- if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd') {
+ if (n !== 'dc' && n !== 'foaf' && n !== '' && n !== 'rdf' && n !== 'cc' && n !== 'ex' && n !== 'sioc' && n !== 'xsd' && n !== 'xml' && n !== 'xmlns') {
ok(false, 'unexpected namespace: ' + n + '=' + namespaces[n]);
}
}
@@ -88,6 +90,14 @@ test("when the namespace hasn't been declared", function() {
equals($('body').xmlns('lic'), undefined);
});
+test("when the namespace is the xml namespace", function () {
+ equals($('body').xmlns('xml'), 'http://www.w3.org/XML/1998/namespace');
+});
+
+test("when the namespace is the xmlns namespace", function () {
+ equals($('body').xmlns('xmlns'), 'http://www.w3.org/2000/xmlns/');
+});
+
module("When setting a namespace");
test("on an element that doesn't have the default namespace declared", function() {

0 comments on commit cc45428

Please sign in to comment.