From 2379b0f31da60a03f0dd9e0350b8dde3d3fe64e8 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Fri, 2 Oct 2015 23:05:08 -0700 Subject: [PATCH] Make 4chan X tolerant of redundant slashes in 4chan URLs. #499 --- src/General/Index.coffee | 6 +++--- src/General/Main.coffee | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/General/Index.coffee b/src/General/Index.coffee index e3d7797ce..9efd4245b 100644 --- a/src/General/Index.coffee +++ b/src/General/Index.coffee @@ -263,7 +263,7 @@ Index = return return if a.textContent is 'Catalog' e.preventDefault() - Index.userPageNav +a.pathname.split('/')[2] or 1 + Index.userPageNav +a.pathname.split(/\/+/)[2] or 1 refreshFront: -> Index.update Index.pushState {page: 1, scroll: true} @@ -275,7 +275,7 @@ Index = if Conf['Index Mode'] in ['all pages', 'catalog'] 1 else - +window.location.pathname.split('/')[2] or 1 + +window.location.pathname.split(/\/+/)[2] or 1 userPageNav: (page) -> state = Index.pushState {page, scroll: true} @@ -323,7 +323,7 @@ Index = mode: Conf['Index Mode'] searched: Index.search oldpage: pageBeforeSearch - , '', pathname + hash + , '', "#{location.protocol}//#{location.host}#{pathname}#{hash}" state saveMode: (mode) -> diff --git a/src/General/Main.coffee b/src/General/Main.coffee index b66891f91..d73262b81 100755 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -21,7 +21,7 @@ Main = g.threads = new SimpleDict() g.posts = new SimpleDict() - pathname = location.pathname.split '/' + pathname = location.pathname.split /\/+/ g.BOARD = new Board pathname[1] return if g.BOARD.ID in ['z', 'fk'] g.VIEW = @@ -119,7 +119,7 @@ Main = when 'i.4cdn.org' $.asap (-> d.readyState isnt 'loading'), -> if Conf['404 Redirect'] and d.title in ['4chan - Temporarily Offline', '4chan - 404 Not Found'] - pathname = location.pathname.split '/' + pathname = location.pathname.split /\/+/ Redirect.navigate 'file', boardID: g.BOARD.ID filename: pathname[pathname.length - 1] @@ -134,10 +134,10 @@ Main = return if Conf['Normalize URL'] and g.VIEW is 'thread' - pathname = location.pathname.split '/' + pathname = location.pathname.split /\/+/ if pathname[2] isnt 'thread' or pathname.length > 4 pathname[2] = 'thread' - history.replaceState null, '', pathname[0...4].join('/') + location.hash + history.replaceState null, '', "#{location.protocol}//#{location.host}#{pathname[0...4].join('/')}#{location.hash}" # c.time 'All initializations' for [name, feature] in Main.features