Skip to content

Commit

Permalink
fix: get ID when colon included (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
laysent authored Oct 13, 2020
1 parent 6e54106 commit 5d24b11
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/getID.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function getID( el )

if( id !== null && id !== '')
{
// if the ID starts with a number selecting with a hash will cause a DOMException
return id.match(/^\d/) ? `[id="${id}"]` : '#' + id;
// if the ID starts with a number or contains ":" selecting with a hash will cause a DOMException
return id.match(/(?:^\d|:)/) ? `[id="${id}"]` : '#' + id;
}
return null;
}
9 changes: 9 additions & 0 deletions test/unique-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ describe( 'Unique Selector Tests', () =>
expect( uniqueSelector ).to.equal( '[id="1so"]' );
} );

it( 'ID', () =>
{
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
$( 'body' ).append( '<div id="api:key" class="test3"></div>' );
const findNode = $( 'body' ).find( '.test3' ).get( 0 );
const uniqueSelector = unique( findNode );
expect( uniqueSelector ).to.equal( '[id="api:key"]' );
} );

it( 'Class', () =>
{
$( 'body' ).get( 0 ).innerHTML = ''; //Clear previous appends
Expand Down

0 comments on commit 5d24b11

Please sign in to comment.