From 8575049de5d98bdbb748c2b608a34eaebc458268 Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Thu, 30 Aug 2012 11:40:07 -0300 Subject: [PATCH] Update get /data Remove leading slash from page Fix edge case with path set to '/' --- .../public/gollum/livepreview/js/livepreview.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js index 911953d8..923f3689 100644 --- a/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js +++ b/lib/gollum/frontend/public/gollum/livepreview/js/livepreview.js @@ -339,15 +339,22 @@ var applyTimeout = function () { ~-1 == false; !~-1 == true; */ if ( !~ location.host.indexOf( 'github.com' ) ) { + + // returns unescaped key with leading slashes removed + function key_no_leading_slash( key ) { + return unescape( $.key( key ) || '' ).replace( /^\/+/, '' ); + } + // ensure leading / is removed from path and that it ends with / - var path = unescape( $.key( 'path' ) || '' ).replace( /^\/+/, '' ); - if ( path.charAt( path.length - 1 ) !== '/' ) { + var path = key_no_leading_slash( 'path' ); + // don't append '/' if path is empty from removing leading slash + if ( path !== '' && path.charAt( path.length - 1 ) !== '/' ) { path += '/'; } jQuery.ajax( { type: 'GET', - url: baseUrl + '/data/' + path + $.key( 'page' ), + url: baseUrl + '/data/' + path + key_no_leading_slash( 'page' ), success: function( data ) { editorSession.setValue( data ); }