From 62f7a59a3246b53b60c98b56b6a91e3a4edb5e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Calvin=20Ju=C3=A1rez?= Date: Tue, 23 Jun 2020 21:03:59 -0600 Subject: [PATCH] Adjust currentAttr.name (fix #318) --- packages/parse5/lib/common/foreign-content.js | 4 ++-- .../parse5/lib/extensions/location-info/tokenizer-mixin.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/parse5/lib/common/foreign-content.js b/packages/parse5/lib/common/foreign-content.js index 10f008b8..dfab15ea 100644 --- a/packages/parse5/lib/common/foreign-content.js +++ b/packages/parse5/lib/common/foreign-content.js @@ -17,7 +17,7 @@ const MIME_TYPES = { //Attributes const DEFINITION_URL_ATTR = 'definitionurl'; const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL'; -const SVG_ATTRS_ADJUSTMENT_MAP = { +const SVG_ATTRS_ADJUSTMENT_MAP = (exports.SVG_ATTRS_ADJUSTMENT_MAP = { attributename: 'attributeName', attributetype: 'attributeType', basefrequency: 'baseFrequency', @@ -76,7 +76,7 @@ const SVG_ATTRS_ADJUSTMENT_MAP = { xchannelselector: 'xChannelSelector', ychannelselector: 'yChannelSelector', zoomandpan: 'zoomAndPan' -}; +}); const XML_ATTRS_ADJUSTMENT_MAP = { 'xlink:actuate': { prefix: 'xlink', name: 'actuate', namespace: NS.XLINK }, diff --git a/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js b/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js index 3c1ef5fb..54658e2f 100644 --- a/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js +++ b/packages/parse5/lib/extensions/location-info/tokenizer-mixin.js @@ -3,6 +3,7 @@ const Mixin = require('../../utils/mixin'); const Tokenizer = require('../../tokenizer'); const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin'); +const SVG_ATTRS_ADJUSTMENT_MAP = require('../../common/foreign-content').SVG_ATTRS_ADJUSTMENT_MAP; class LocationInfoTokenizerMixin extends Mixin { constructor(tokenizer) { @@ -37,7 +38,9 @@ class LocationInfoTokenizerMixin extends Mixin { currentToken.location.attrs = Object.create(null); } - currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation; + const name = SVG_ATTRS_ADJUSTMENT_MAP[currentAttr.name] || currentAttr.name; + + currentToken.location.attrs[name] = this.currentAttrLocation; } _getOverriddenMethods(mxn, orig) {