moddle-xml
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -710,2 +710,21 @@ 'use strict'; | ||
var ENCODING_PATTERN = /^<\?xml.* encoding="([^"]+)"(?: .*)?\?>$/i; | ||
var UTF_8_PATTERN = /^utf-8$/i; | ||
function handleQuestion(question) { | ||
var match = ENCODING_PATTERN.exec(question); | ||
var encoding = match && match[1]; | ||
if (!encoding || UTF_8_PATTERN.test(encoding)) { | ||
return; | ||
} | ||
context.addWarning({ | ||
message: | ||
'unsupported document encoding <' + encoding + '>, ' + | ||
'falling back to UTF-8' | ||
}); | ||
} | ||
function handleOpen(node, getContext) { | ||
@@ -770,2 +789,3 @@ var handler = stack.peek(); | ||
}) | ||
.on('question', handleQuestion) | ||
.on('closeTag', handleClose) | ||
@@ -772,0 +792,0 @@ .on('cdata', handleCData) |
{ | ||
"name": "moddle-xml", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "XML import/export for documents described with moddle", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -2097,2 +2097,66 @@ 'use strict'; | ||
describe('encoding', function() { | ||
var model = createModel([ 'properties' ]); | ||
it('should decode UTF-8, no problemo', function(done) { | ||
// given | ||
var reader = new Reader(model); | ||
var rootHandler = reader.handler('props:ComplexAttrs'); | ||
var xml = | ||
'<?xml version="1.0" encoding="utf-8"?>' + | ||
'<props:complexAttrs xmlns:props="http://properties">' + | ||
'</props:complexAttrs>'; | ||
// when | ||
reader.fromXML(xml, rootHandler, function(err, result, context) { | ||
// then | ||
expect(err).not.to.exist; | ||
expect(context.warnings).to.be.empty; | ||
expect(result).to.exist; | ||
expect(context).to.exist; | ||
done(); | ||
}); | ||
}); | ||
it('should warn on non-UTF-8 encoded files', function(done) { | ||
// given | ||
var reader = new Reader(model); | ||
var rootHandler = reader.handler('props:ComplexAttrs'); | ||
var xml = | ||
'<?xml version="1.0" encoding="windows-1252"?>' + | ||
'<props:complexAttrs xmlns:props="http://properties">' + | ||
'</props:complexAttrs>'; | ||
// when | ||
reader.fromXML(xml, rootHandler, function(err, result, context) { | ||
// then | ||
expect(err).not.to.exist; | ||
var warnings = context.warnings; | ||
expect(warnings).to.have.length(1); | ||
expect(warnings[0].message).to.match(/unsupported document encoding <windows-1252>/); | ||
expect(result).to.exist; | ||
expect(context).to.exist; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
145360
4180