diff --git a/src/__tests__/attributes.js b/src/__tests__/attributes.js index d7637d8..c4c08fc 100644 --- a/src/__tests__/attributes.js +++ b/src/__tests__/attributes.js @@ -447,3 +447,17 @@ testDeprecation('smart quotes', '[data-foo=bar]', (t, tree) => { attr.setValue('smart with "double quotes"', {smart: true}); t.deepEqual(attr.toString(), "[data-foo='smart with \"double quotes\"']"); }); + +testDeprecation('set Attribute#quoteMark', '[data-foo=bar]', (t, tree) => { + let attr = tree.nodes[0].nodes[0]; + attr.quoteMark = '"'; + t.deepEqual(attr.toString(), '[data-foo="bar"]'); + attr.quoteMark = "'"; + t.deepEqual(attr.toString(), "[data-foo='bar']"); + attr.quoteMark = null; + t.deepEqual(attr.toString(), "[data-foo=bar]"); + attr.value = "has space"; + t.deepEqual(attr.toString(), "[data-foo=has\\ space]"); + attr.quoteMark = '"'; + t.deepEqual(attr.toString(), '[data-foo="has space"]'); +}); diff --git a/src/selectors/attribute.js b/src/selectors/attribute.js index 7122f34..75aa093 100644 --- a/src/selectors/attribute.js +++ b/src/selectors/attribute.js @@ -218,7 +218,9 @@ export default class Attribute extends Namespace { _syncRawValue () { let rawValue = cssesc(this._value, CSSESC_QUOTE_OPTIONS[this.quoteMark]); if (rawValue === this._value) { - delete this.raws.value; + if (this.raws) { + delete this.raws.value; + } } else { this.raws.value = rawValue; } @@ -262,12 +264,8 @@ export default class Attribute extends Namespace { return; } this._value = unescaped; - this.quoteMark = quoteMark; - if (unescaped === this._value) { - delete this.raws.value; - } else { - this.raws.value = v; - } + this._quoteMark = quoteMark; + this._syncRawValue(); } else { this._value = v; }