@@ -209,6 +209,55 @@ def test_jinja_bad_path(self, app: Sphinx, ensure_redirect):
209209
210210 ensure_redirect ("another.html" , "index.html" )
211211
212+ @pytest .mark .sphinx ("html" , testroot = "pass_url_fragments_queries" )
213+ def test_pass_url_fragments (self , app : Sphinx , _sb : BaseCase , ensure_redirect ):
214+ app .build ()
215+
216+ ensure_redirect ("another.html" , "index.html" )
217+ _sb .open (rel2url (app .outdir , "another.html" ) + "#haha" )
218+ # check url
219+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
220+ _sb .execute_script (
221+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
222+ )
223+ )
224+ # check hash
225+ assert "#haha" == _sb .execute_script ("return window.location.hash" )
226+
227+ @pytest .mark .sphinx ("html" , testroot = "pass_url_fragments_queries" )
228+ def test_pass_url_queries (self , app : Sphinx , _sb : BaseCase , ensure_redirect ):
229+ app .build ()
230+
231+ ensure_redirect ("another.html" , "index.html" )
232+ _sb .open (rel2url (app .outdir , "another.html" ) + "?phrase=haha" )
233+ # check url
234+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
235+ _sb .execute_script (
236+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
237+ )
238+ )
239+ # check query
240+ assert "?phrase=haha" == _sb .execute_script ("return window.location.search" )
241+
242+ @pytest .mark .sphinx ("html" , testroot = "pass_url_fragments_queries" )
243+ def test_pass_url_fragment_and_query (
244+ self , app : Sphinx , _sb : BaseCase , ensure_redirect
245+ ):
246+ app .build ()
247+
248+ ensure_redirect ("another.html" , "index.html" )
249+ _sb .open (rel2url (app .outdir , "another.html" ) + "?phrase=haha#giraffe" )
250+ # check url
251+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
252+ _sb .execute_script (
253+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
254+ )
255+ )
256+ # check query
257+ assert "?phrase=haha" == _sb .execute_script ("return window.location.search" )
258+ # check hash
259+ assert "#giraffe" == _sb .execute_script ("return window.location.hash" )
260+
212261
213262class TestExtDirHtml :
214263 @pytest .mark .sphinx ("dirhtml" , testroot = "no_redirects" )
@@ -402,3 +451,52 @@ def test_jinja_bad_path(self, app: Sphinx, ensure_redirect):
402451 assert app .statuscode == 0
403452
404453 ensure_redirect ("another/index.html" , "index.html" )
454+
455+ @pytest .mark .sphinx ("dirhtml" , testroot = "pass_url_fragments_queries" )
456+ def test_pass_url_fragments (self , app : Sphinx , _sb : BaseCase , ensure_redirect ):
457+ app .build ()
458+
459+ ensure_redirect ("another/index.html" , "index.html" )
460+ _sb .open (rel2url (app .outdir , "another/index.html" ) + "#haha" )
461+ # check url
462+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
463+ _sb .execute_script (
464+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
465+ )
466+ )
467+ # check hash
468+ assert "#haha" == _sb .execute_script ("return window.location.hash" )
469+
470+ @pytest .mark .sphinx ("dirhtml" , testroot = "pass_url_fragments_queries" )
471+ def test_pass_url_queries (self , app : Sphinx , _sb : BaseCase , ensure_redirect ):
472+ app .build ()
473+
474+ ensure_redirect ("another/index.html" , "index.html" )
475+ _sb .open (rel2url (app .outdir , "another/index.html" ) + "?phrase=haha" )
476+ # check url
477+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
478+ _sb .execute_script (
479+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
480+ )
481+ )
482+ # check query
483+ assert "?phrase=haha" == _sb .execute_script ("return window.location.search" )
484+
485+ @pytest .mark .sphinx ("dirhtml" , testroot = "pass_url_fragments_queries" )
486+ def test_pass_url_fragment_and_query (
487+ self , app : Sphinx , _sb : BaseCase , ensure_redirect
488+ ):
489+ app .build ()
490+
491+ ensure_redirect ("another/index.html" , "index.html" )
492+ _sb .open (rel2url (app .outdir , "another/index.html" ) + "?phrase=haha#giraffe" )
493+ # check url
494+ assert Path (rel2url (app .outdir , "index.html" )) == Path (
495+ _sb .execute_script (
496+ 'return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname'
497+ )
498+ )
499+ # check query
500+ assert "?phrase=haha" == _sb .execute_script ("return window.location.search" )
501+ # check hash
502+ assert "#giraffe" == _sb .execute_script ("return window.location.hash" )
0 commit comments