diff --git a/src/core/selector-type.js b/src/core/selector-type.js index 7434df4..b1f3dd3 100644 --- a/src/core/selector-type.js +++ b/src/core/selector-type.js @@ -45,19 +45,19 @@ const SelectorCategoryRegex = { const SelectorTypeRegex = { None : '', Invalid : '', - Universal : /\*/, - Type : /^[A-Za-z]+$/, - TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/, - TypeId : /^[A-Za-z]+\#[A-Za-z]+$/, - Class : /^\.[A-Za-z]+$/, - Id : /^\#[A-Za-z]+$/, - Attribute : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr] - AttributeExact : /^[A-Za-z]+\[[A-Za-z]+\=\"[A-Za-z]+\"\]$/, // E[attr=value] - AttributeExactHyphen : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr|=value] - AttributeList : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr~=value] - AttributePrefix : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr^=value] - AttributeSuffix : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr$=value] - AttributeContains : /^[A-Za-z]+\[[A-Za-z]+\]$/ // E[attr*=value] + Universal : /\*/, // * + Type : /^[A-Za-z]+$/, // E + TypeClass : /^[A-Za-z]+\.[A-Za-z]+$/, // E.Class + TypeId : /^[A-Za-z]+\#[A-Za-z]+$/, // E#Id + Class : /^\.[A-Za-z]+$/, // .Class + Id : /^\#[A-Za-z]+$/, // #Id + Attribute : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr] + AttributeExact : /^[A-Za-z]+\[[A-Za-z]+\=\"[A-Za-z]+\"\]$/, // E[attr=value] + AttributeExactHyphen : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr|=value] + AttributeList : /^[A-Za-z]+\[[A-Za-z]+\]$/, // E[attr~=value] + AttributePrefix : /^[A-Za-z]+\[[A-Za-z]+\^\=\"[A-Za-z]+\"\]$/, // E[attr^=value] + AttributeSuffix : /^[A-Za-z]+\[[A-Za-z]+\$\=\"[A-Za-z]+\"\]$/, // E[attr$=value] + AttributeContains : /^[A-Za-z]+\[[A-Za-z]+\]$/ // E[attr*=value] }; /** @@ -77,7 +77,9 @@ export default function getType(selector) { } if (SelectorCategoryRegex.Attribute.test(selector)) { - return SelectorTypeRegex.AttributeExact.test(selector) ? SelectorType.AttributeExact : + return SelectorTypeRegex.AttributePrefix.test(selector) ? SelectorType.AttributePrefix : + SelectorTypeRegex.AttributeSuffix.test(selector) ? SelectorType.AttributeSuffix : + SelectorTypeRegex.AttributeExact.test(selector) ? SelectorType.AttributeExact : SelectorTypeRegex.Attribute.test(selector) ? SelectorType.Attribute : SelectorType.Invalid; } diff --git a/test/get-type.js b/test/get-type.js index 603d89b..be54011 100644 --- a/test/get-type.js +++ b/test/get-type.js @@ -20,6 +20,14 @@ describe('getType(selector)', function() { expect(getType('a[href="a"]')).to.equal(SelectorType.AttributeExact); }); + it('Attribute prefix selector (E[foo^="bar"])', () => { + expect(getType('a[href^="a"]')).to.equal(SelectorType.AttributePrefix); + }); + + it('Attribute suffix selector (E[foo$="bar"])', () => { + expect(getType('a[href$="a"]')).to.equal(SelectorType.AttributeSuffix); + }); + it('Class selector (.class)', () => { expect(getType('.class')).to.equal(SelectorType.Class); });