rdfxml-streaming-parser
Advanced tools
Comparing version 1.2.0 to 1.2.1
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
<a name="v1.2.1"></a> | ||
## [v1.2.1](https://github.com/rdfjs/rdfxml-streaming-parser.js/compare/v1.2.0...v1.2.1) - 2019-04-02 | ||
### Fixed | ||
* [Fix doctype entities not being considered in base IRIs, Closes #10](https://github.com/rdfjs/rdfxml-streaming-parser.js/commit/3cda7e18839200e1130af06de23128dd56f24e41) | ||
<a name="v1.2.0"></a> | ||
@@ -5,0 +11,0 @@ ## [v1.2.0](https://github.com/rdfjs/rdfxml-streaming-parser.js/compare/v1.1.0...v1.2.0) - 2019-01-28 |
/// <reference types="node" /> | ||
import * as RDF from "rdf-js"; | ||
import { Tag } from "sax"; | ||
import { SAXParser, Tag } from "sax"; | ||
import { Transform, TransformCallback } from "stream"; | ||
@@ -48,2 +48,9 @@ import EventEmitter = NodeJS.EventEmitter; | ||
/** | ||
* Expand the given term based on the DOCTYPE entities. | ||
* @param {string} term A term. | ||
* @param {SAXParser} parser A SAX parser that has DOCTYPE entities. | ||
* @return {string} The expanded or same term. | ||
*/ | ||
static expandDoctypeEntity(term: string, parser: SAXParser): string; | ||
/** | ||
* Parses the given text stream into a quad stream. | ||
@@ -50,0 +57,0 @@ * @param {NodeJS.EventEmitter} stream A text stream. |
@@ -99,2 +99,23 @@ "use strict"; | ||
/** | ||
* Expand the given term based on the DOCTYPE entities. | ||
* @param {string} term A term. | ||
* @param {SAXParser} parser A SAX parser that has DOCTYPE entities. | ||
* @return {string} The expanded or same term. | ||
*/ | ||
static expandDoctypeEntity(term, parser) { | ||
if (term[0] === '&') { | ||
const prefixEndPos = term.indexOf(';'); | ||
if (prefixEndPos > 0) { | ||
const prefix = term.substr(1, prefixEndPos - 1); | ||
const entities = parser.ENTITIES; | ||
const expandedPrefix = entities[prefix]; | ||
if (expandedPrefix) { | ||
const suffix = term.substr(prefixEndPos); | ||
term = expandedPrefix + suffix; | ||
} | ||
} | ||
} | ||
return term; | ||
} | ||
/** | ||
* Parses the given text stream into a quad stream. | ||
@@ -282,3 +303,4 @@ * @param {NodeJS.EventEmitter} stream A text stream. | ||
else if (attributeKeyExpanded.local === 'base') { | ||
activeTag.baseIRI = attributeValue; | ||
// SAX Parser does not expand xml:base, based on DOCTYPE, so we have to do it manually | ||
activeTag.baseIRI = RdfXmlParser.expandDoctypeEntity(attributeValue, this.saxStream._parser); | ||
continue; | ||
@@ -595,3 +617,3 @@ } | ||
onDoctype(doctype) { | ||
doctype.replace(/<!ENTITY ([^ ]+) "([^"]+)">/g, (match, prefix, uri) => { | ||
doctype.replace(/<!ENTITY ([^ ]+) "([^"]+)" *>/g, (match, prefix, uri) => { | ||
this.saxStream._parser.ENTITIES[prefix] = uri; | ||
@@ -598,0 +620,0 @@ return ''; |
{ | ||
"name": "rdfxml-streaming-parser", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "Streaming RDF/XML parser", | ||
@@ -35,3 +35,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@types/jest": "^23.3.0", | ||
"@types/jest": "^24.0.0", | ||
"@types/minimist": "^1.2.0", | ||
@@ -41,3 +41,3 @@ "@types/sax": "^1.0.1", | ||
"coveralls": "^3.0.0", | ||
"jest": "^23.4.1", | ||
"jest": "^24.3.0", | ||
"jest-rdf": "^1.3.0", | ||
@@ -49,3 +49,3 @@ "manual-git-changelog": "^1.0.0", | ||
"streamify-string": "^1.0.1", | ||
"ts-jest": "^23.10.0", | ||
"ts-jest": "^24.0.0", | ||
"tslint": "^5.8.0", | ||
@@ -61,3 +61,5 @@ "tslint-eslint-rules": "^5.3.1", | ||
}, | ||
"setupTestFrameworkScriptFile": "jest-rdf", | ||
"setupFilesAfterEnv": [ | ||
"jest-rdf" | ||
], | ||
"transform": { | ||
@@ -64,0 +66,0 @@ "^.+\\.ts$": "ts-jest" |
@@ -66,3 +66,2 @@ # RDF/XML Streaming Parser | ||
myParser.write(`<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">`); | ||
myParser.write(`<rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">`); | ||
myParser.write(`<ex:prop />`); | ||
@@ -69,0 +68,0 @@ myParser.write(`</rdf:Description>`); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49334
835
111