Skip to content

Commit

Permalink
Merge pull request #5 from hildjj/conformance-ns
Browse files Browse the repository at this point in the history
Switch namespacing off as appropriate in conformance tests
  • Loading branch information
hildjj committed May 10, 2023
2 parents 7282b14 + 569841b commit c238765
Show file tree
Hide file tree
Showing 49 changed files with 295 additions and 429 deletions.
8 changes: 4 additions & 4 deletions docs/AttlistDecl.html

Large diffs are not rendered by default.

150 changes: 146 additions & 4 deletions docs/Attribute.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/AttributeDecl.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/CdataSection.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Comment.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/DoctypeDecl.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Document.html

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions docs/DomParser.html

Large diffs are not rendered by default.

220 changes: 7 additions & 213 deletions docs/Element.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/ElementDecl.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/EntityDecl.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/Namespace.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/Namespace_Namespace.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/Node.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/NotationDecl.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/ParentNode.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/ProcessingInstruction.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/Text.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/XPath.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/XPathSyntaxError.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/XmlDeclaration.html

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions docs/dom.js.html

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions docs/domParser.js.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-ConstructorParameters.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Exclude.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Extract.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-InstanceType.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-NonNullable.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Omit.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-OmitThisParameter.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Parameters.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Partial.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Pick.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Readonly.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Record.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-Required.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-ReturnType.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-ThisParameterType.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/external-ThisType.html

Large diffs are not rendered by default.

77 changes: 1 addition & 76 deletions docs/global.html

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions docs/index.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docs/xpath.js.html

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions lib/dom.js
Expand Up @@ -462,6 +462,7 @@ export class Element extends ParentNode {
* @param {string} [ns] the namespace to search for. If not given, match
* attributes in any namespace.
* @returns {Attribute|undefined} Attribute, if one that matches is found
* @private
*/
_attribute(local, ns) {
return this.att.find(a => (
Expand Down Expand Up @@ -574,9 +575,9 @@ export class Element extends ParentNode {
ret += color(this.name.prefix, NAME, options)
ret += color(':', PUNCTUATION, options)
}
ret += color(this.name.local, NAME, options) +
this.ns.map(n => n.toString(options)).join('') +
this.att.map(a => a.toString(options)).join('')
ret += color(this.name.local, NAME, options)
ret += this.ns.map(n => n.toString(options)).join('')
ret += this.att.map(a => a.toString(options)).join('')
if (this.children.length > 0) {
ret += color('>', PUNCTUATION, options)
ret += super.toString(options) // All children
Expand Down Expand Up @@ -646,11 +647,11 @@ export class Attribute extends Node {
*/
constructor(name, value) {
super()
if (typeof name === 'string') {
this.name = {local: name}
} else {
this.name = name
}

/** @type {Pieces} */
this.name = (typeof name === 'string') ? {local: name} : name

/** @type {string} */
this.value = value
}

Expand Down
2 changes: 0 additions & 2 deletions lib/domParser.js
Expand Up @@ -76,8 +76,6 @@ export class DomParser {
* Encoding to expect from Buffers/etc that are passed to parse()
*/
constructor(options) {
// Separator is always '|'. We're always going to take care of namespace
// triples before the user sees them.
this.#parser = new XmlParser(options)

if (options?.xmlBase) {
Expand Down
1 change: 1 addition & 0 deletions lib/xpath.js
Expand Up @@ -55,6 +55,7 @@ export class XPathSyntaxError extends Error {

/**
* @type {Record<string,XPathFun>}
* @private
*/
const XPathFunctions = {
count(context) {
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -27,11 +27,11 @@
"author": "Joe Hildebrand <joe-github@cursive.net>",
"license": "MIT",
"dependencies": {
"expat-wasm": "3.1.0"
"expat-wasm": "3.1.2"
},
"devDependencies": {
"@cto.af/eslint-config": "1.0.5",
"@types/node": "20.1.0",
"@cto.af/eslint-config": "1.1.0",
"@types/node": "20.1.2",
"ava": "^5.2.0",
"c8": "7.13.0",
"docdash": "2.0.1",
Expand Down
18 changes: 10 additions & 8 deletions test/conformance.ava.js
@@ -1,5 +1,6 @@
import {DomParser, NS} from '../lib/index.js'
import {fileURLToPath, pathToFileURL} from 'url'
import {XmlParser} from 'expat-wasm'
import fs from 'fs'
import path from 'path'
import test from 'ava'
Expand All @@ -9,10 +10,11 @@ const __dirname = path.dirname(__filename)

const root = pathToFileURL(__dirname).toString()

function parseFile(name) {
function parseFile(name, noNS) {
return fs.promises.readFile(name).then(buf => DomParser.parseFull(buf, {
base: name.toString(),
xmlBase: true,
separator: noNS ? XmlParser.NO_NAMESPACES : '|',
systemEntity(base, sysId, pubId) {
const newBase = new URL(sysId, base)
const bs = newBase.toString()
Expand All @@ -34,8 +36,7 @@ const confnameURL = new URL(
const conf = await parseFile(confnameURL)

const skip = {
'valid-sa-012': 'expat issue 1, always uses 1.1 rules for attribute name containing only colon',
'rmt-e2e-50': 'potential expat issue 4, does not allow U+0085 as whitespace',
'rmt-e2e-50': 'this can only be tested effectively in XML 1.1, since CR is in the S production; in 1.1 we can use NEL which isn\'t.',
}

/**
Expand All @@ -57,19 +58,20 @@ async function execTests(el, base, t) {
'XML1.0-errata2e',
'XML1.0-errata3e',
// 'NS1.1',
// 'XML1.0-errata4e', See: https://github.com/libexpat/libexpat/issues/171
// 'XML1.1', See: https://github.com/libexpat/libexpat/issues/378
//
// 'XML1.0-errata4e', // See: https://github.com/libexpat/libexpat/issues/171
// 'XML1.1', // See: https://github.com/libexpat/libexpat/issues/378
].indexOf(rec) !== -1) {
const id = el.attr('ID')
const reason = skip[id]
const noNS = el.attr('NAMESPACE').toUpperCase() === 'NO'

if (reason) {
const uri = new URL(el.attr('URI'), base)
t.throwsAsync(() => parseFile(uri), undefined, id)
t.throwsAsync(() => parseFile(uri, noNS), undefined, id)
} else {
const uri = new URL(el.attr('URI'), base)
if (el.attr('TYPE') === 'valid') {
const doc = await parseFile(uri)
const doc = await parseFile(uri, noNS)
t.truthy(doc, id)
}
}
Expand Down
5 changes: 4 additions & 1 deletion types/dom.d.ts
Expand Up @@ -175,8 +175,9 @@ export class Element extends ParentNode {
* @param {string} [ns] the namespace to search for. If not given, match
* attributes in any namespace.
* @returns {Attribute|undefined} Attribute, if one that matches is found
* @private
*/
_attribute(local: string, ns?: string | undefined): Attribute | undefined;
private _attribute;
/**
* Find the value of an attribute that matches the given local name and
* namespace.
Expand Down Expand Up @@ -243,7 +244,9 @@ export class Attribute extends Node {
* @param {string} value The value
*/
constructor(name: string | Pieces, value: string);
/** @type {Pieces} */
name: Pieces;
/** @type {string} */
value: string;
}
/**
Expand Down

0 comments on commit c238765

Please sign in to comment.