Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double Forward Slash in Some URLs #123

Closed
zeroflags opened this issue Jan 10, 2018 · 1 comment · May be fixed by #298
Closed

Double Forward Slash in Some URLs #123

zeroflags opened this issue Jan 10, 2018 · 1 comment · May be fixed by #298

Comments

@zeroflags
Copy link

zeroflags commented Jan 10, 2018

I found out a small discrepancy in various taxonomy URLs, some of which produce an additional forward slash (resulting in a double forward slash) in links on the default page as well as in menu links.

The first problem is in the layouts/index.html file:

$ diff -u layouts/index-original.html layouts/index.html
--- layouts/index-original.html	2018-01-11 10:37:56.684475367 +1100
+++ layouts/index.html	2018-01-10 21:25:48.937303363 +1100
@@ -37,7 +37,7 @@
               {{ if .Params.tags }}
                 <span class="post-meta">
                 {{ range .Params.tags }}
-                  #<a href="{{ $.Site.LanguagePrefix | absURL }}/tags/{{ . | urlize }}/">{{ . }}</a>&nbsp;
+                  #<a href="{{ $.Site.LanguagePrefix | absURL }}tags/{{ . | urlize }}/">{{ . }}</a>&nbsp;
                 {{ end }}
                 </span>
               {{ end }}

This is quite interesting, as exactly the same code is present in layouts/_default/list.html where it does not contain the beginning forward slash in the /tags/ string (as expected).

A similar problem occurs in layouts/_default/terms.html file:

$ diff -u layouts/_default/terms-original.html layouts/_default/terms.html
--- layouts/_default/terms-original.html	2018-01-11 10:16:41.184693213 +1100
+++ layouts/_default/terms.html	2018-01-11 10:16:29.424604385 +1100
@@ -4,7 +4,7 @@
     <article class="post-preview">
       <div class="list-group col-lg-4 col-lg-offset-4 col-md-6 col-md-offset-3">
       {{ range $key, $value := .Data.Terms.ByCount }}
-      <a href="{{ $.Site.LanguagePrefix | absURL }}/{{ $data.Plural }}/{{ $value.Name | urlize }}/" class="list-group-item">
+      <a href="{{ $.Site.LanguagePrefix | absURL }}{{ $data.Plural }}/{{ $value.Name | urlize }}/" class="list-group-item">
           {{ $value.Name }}<span class="badge">{{ $value.Count }}</span></a>
       {{ end }}
       </div>

The last problem I found was in partials/nav.html file:

$ diff -u layouts/partials/nav-original.html layouts/partials/nav.html
--- layouts/partials/nav-original.html	2018-01-11 09:40:21.323002834 +1100
+++ layouts/partials/nav.html	2018-01-11 09:34:49.237422460 +1100
@@ -11,6 +11,7 @@
     </div>
 
     <div class="collapse navbar-collapse" id="main-navbar">
+      {{ $url := urls.Parse $.Site.BaseURL }}
       <ul class="nav navbar-nav navbar-right">
         {{ range .Site.Menus.main.ByWeight }}
           {{ if .HasChildren }}
@@ -18,13 +19,13 @@
               <a class="navlinks-parent" href="javascript:void(0)">{{ .Name }}</a>
               <div class="navlinks-children">
                 {{ range .Children }}
-                  <a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
+                  <a href="{{ replace .URL $url.Path "" | relLangURL }}">{{ .Name }}</a>
                 {{ end }}
               </div>
             </li>
           {{ else }}
             <li>
-              <a title="{{ .Name }}" href="{{ .URL | relLangURL }}">{{ .Name }}</a>
+              <a title="{{ .Name }}" href="{{ replace .URL $url.Path "" | relLangURL }}">{{ .Name }}</a>
             </li>
           {{ end }}
         {{ end }}

Here, the whole URL was injected two times with the same server path (taken from config files baseURL variable?). I mean, let's assume that: baseURL="https://www.domain.tld/blog/". After the compilation, it resulted in menu nav links to look like: https://www.domain.tld/blog/blog/tags/ or https://www.domain.tld/blog/blog/categories/, and that is undesirable.


Note: I do not use the Multilingual Mode. Hopefully, this will not break it.

Many thanks and regards!

@zeroflags zeroflags changed the title Double Forward Slash in URLs on Default Page Double Forward Slash in Some URLs Jan 10, 2018
@zeroflags
Copy link
Author

I found out that the problem is more complex and the above proposed solution does not sanitize all of the possible issues. I am better closing this before causing more harm than good.

Anyway, many thanks to everyone involved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant