limit named links to [a-zA-Z0-9\-\_\:\.] #836

This commit is contained in:
Hakim El Hattab 2014-03-25 15:12:10 +01:00
parent 3d7c21256c
commit da82c8ce81
2 changed files with 22 additions and 7 deletions

View File

@ -2274,8 +2274,16 @@ var Reveal = (function(){
// If the first bit is invalid and there is a name we can // If the first bit is invalid and there is a name we can
// assume that this is a named link // assume that this is a named link
if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) { if( isNaN( parseInt( bits[0], 10 ) ) && name.length ) {
// Find the slide with the specified name var element;
var element = document.querySelector( '#' + name );
try {
// Find the slide with the specified name
element = document.querySelector( '#' + name );
}
catch( e ) {
// If the ID is an invalid selector a harmless SyntaxError
// may be thrown here.
}
if( element ) { if( element ) {
// Find the position of the named slide and navigate to it // Find the position of the named slide and navigate to it
@ -2320,9 +2328,16 @@ var Reveal = (function(){
else { else {
var url = '/'; var url = '/';
// Attempt to create a named link based on the slide's ID
var id = currentSlide.getAttribute( 'id' );
if( id ) {
id = id.toLowerCase();
id = id.replace( /[^a-zA-Z0-9\-\_\:\.]/g, '' );
}
// If the current slide has an ID, use that as a named link // If the current slide has an ID, use that as a named link
if( currentSlide && typeof currentSlide.getAttribute( 'id' ) === 'string' ) { if( currentSlide && typeof id === 'string' && id.length ) {
url = '/' + currentSlide.getAttribute( 'id' ); url = '/' + id;
} }
// Otherwise use the /h/v index // Otherwise use the /h/v index
else { else {

6
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long