File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -233,9 +233,13 @@ proto.updateGetPathTemplate = function( optPath ) {
233233 } . bind ( this ) ;
234234 // get pageIndex from location
235235 // convert path option into regex to look for pattern in location
236- var regexString = optPath . replace ( '{{#}}' , '(\\d\\d?\\d?)' ) ;
236+ // escape query (?) in url, allows for parsing GET parameters
237+ var regexString = optPath
238+ . replace ( / (?< ! \\ ) \? / , '\\?' )
239+ . replace ( '{{#}}' , '(\\d\\d?\\d?)' ) ;
237240 var templateRe = new RegExp ( regexString ) ;
238241 var match = location . href . match ( templateRe ) ;
242+
239243 if ( match ) {
240244 this . pageIndex = parseInt ( match [ 1 ] , 10 ) ;
241245 this . log ( 'pageIndex' , [ this . pageIndex , 'template string' ] ) ;
Original file line number Diff line number Diff line change @@ -26,4 +26,29 @@ QUnit.test( 'pageIndex', function( assert ) {
2626
2727 history . replaceState ( null , document . title , prevURL ) ;
2828
29+ infScroll . destroy ( ) ;
30+
31+ history . replaceState ( null , document . title , 'page?currPage=8' ) ;
32+ infScroll = new InfiniteScroll ( demoElem , {
33+ path : 'page?currPage={{#}}' ,
34+ history : false ,
35+ scrollThreshold : false ,
36+ } ) ;
37+
38+ assert . equal ( infScroll . pageIndex , 8 , 'pageIndex from GET param with {{#}}' ) ;
39+
40+ history . replaceState ( null , document . title , prevURL ) ;
41+
42+ infScroll . destroy ( ) ;
43+
44+ history . replaceState ( null , document . title , 'page?currPage=8' ) ;
45+ infScroll = new InfiniteScroll ( demoElem , {
46+ path : 'page\\?currPage={{#}}' ,
47+ history : false ,
48+ scrollThreshold : false ,
49+ } ) ;
50+
51+ assert . equal ( infScroll . pageIndex , 8 , 'pageIndex from GET param with {{#}} and pre-escaped regexp' ) ;
52+
53+ history . replaceState ( null , document . title , prevURL ) ;
2954} ) ;
You can’t perform that action at this time.
0 commit comments