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

Slashes in a taxonomy term break path resolution #4090

Closed
tsuereth opened this issue Nov 16, 2017 · 10 comments · Fixed by #4388
Closed

Slashes in a taxonomy term break path resolution #4090

tsuereth opened this issue Nov 16, 2017 · 10 comments · Fixed by #4388

Comments

@tsuereth
Copy link

My blog is about video games. So for the taxonomy "games" I have terms such as:

  • Kingdom Hearts 358/2 Days
  • Retro/Grade
  • SHENZHEN I/O

When these taxonomy terms are translated into url-safe slugs, the slashes are left untouched. As a result, the website path to the page for SHENZHEN I/O would be something like /games/shenzhen-i/o/

This subsequently breaks the mapping of path "sections" to meaningful information. When hugo renders content for games/shenzhen-i/o it breaks the path into the sections "games" (the parent taxonomy), then "shenzhen-i" (the taxonomy term), then "o" (which is discarded?).

So when a content template looks for pages tagged with the matching taxonomy term, it ends up looking for "SHENZHEN I" -- which doesn't match my posts for "SHENZHEN I/O"

@bep
Copy link
Member

bep commented Nov 24, 2017

I assume you know that you can have content files with proper titles for your terms?

So "Retro-Grade" (term) can easily have a title with slashes or whatever.

@tsuereth
Copy link
Author

I hadn't considered that option, and it does provide a workaround for me; which won't be terribly difficult to maintain, given how few titles have this problem. Thanks for the suggestion!

It's still a bit non-ideal, since my content will have to remember to use "Retro-Grade" to reference the game "Retro/Grade"

Following the discussion on #4092 , and given that I no longer need a template function for "segment" versus full-path sanitization; would you agree with the longer-term goal of cleaning up how Hugo joins paths together? (To ensure that paths made of "partOne" "part/Two" "partThree" doesn't include a spurious slash in the second part.)

@tsuereth
Copy link
Author

On further testing, this workaround actually isn't sufficient for my use-case.

  • If I make a content file for the Retro/Grade term at content/games/retro-grade/_index.md then references to a term like "Retro-Grade" will resolve it; and if I set the title in this content file to "Retro/Grade" then that term's page will display the title I want.

  • However, if I associate a post or page with the game "Retro-Grade" (i.e. games = ["Retro-Grade"]) then the only content I can display on that post/page is "Retro-Grade" -- I don't believe there is a way to reverse-lookup the term title "Retro/Grade" from a pre-sanitized string.

moorereason added a commit to moorereason/hugo that referenced this issue Feb 8, 2018
Add tests with slashes in terms to illuminate failing code paths.

Updates gohugoio#4090
moorereason added a commit to moorereason/hugo that referenced this issue Feb 8, 2018
MakePathSegment properly sanitizes path segments (like taxonomy terms) with
slashes (and pound signs).

Updates gohugoio#4090
moorereason added a commit to moorereason/hugo that referenced this issue Feb 8, 2018
This commit attempts to sanitize term keys and path segments to fix the
handling of taxonomy terms containing slashes.

Based upon gohugoio#4092 by @tsuereth.

Fixes gohugoio#4090
@stale
Copy link

stale bot commented Feb 23, 2018

This issue has been automatically marked as stale because it has not had recent activity. The resources of the Hugo team are limited, and so we are asking for your help.
If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.
If this is a feature request, and you feel that it is still relevant and valuable, please tell us why.
This issue will automatically be closed in the near future if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Stale label Feb 23, 2018
@moorereason moorereason added Keep and removed Stale labels Feb 23, 2018
moorereason added a commit to moorereason/hugo that referenced this issue Aug 21, 2018
Add tests with slashes in terms to illuminate failing code paths.

Updates gohugoio#4090
moorereason added a commit to moorereason/hugo that referenced this issue Aug 21, 2018
MakePathSegment properly sanitizes path segments (like taxonomy terms) with
slashes (and pound signs).

Updates gohugoio#4090
moorereason added a commit to moorereason/hugo that referenced this issue Aug 21, 2018
This commit attempts to sanitize term keys and path segments to fix the
handling of taxonomy terms containing slashes.

Based upon gohugoio#4092 by @tsuereth.

Fixes gohugoio#4090
@bep bep closed this as completed in #4388 Aug 22, 2018
bep pushed a commit that referenced this issue Aug 22, 2018
@bep bep added this to the v0.48 milestone Aug 22, 2018
@moorereason moorereason reopened this Dec 14, 2018
@moorereason
Copy link
Contributor

The fix for this issue has been reverted in #5519. Discussions on fixing this without breaking sites that depend on this "feature" can be found in #5520.

@moorereason moorereason modified the milestones: v0.48, v0.54 Dec 14, 2018
@bep
Copy link
Member

bep commented Dec 14, 2018

@moorereason are you sure? That was not the intention, and there were'nt any existing breaking tests ...

@moorereason
Copy link
Contributor

Then I'm mistaken. Thanks for setting me straight. 👍

@bep bep added this to the v0.100.0 milestone May 24, 2022
@bep bep modified the milestones: v0.100.0, v0.101.0 May 31, 2022
@bep bep modified the milestones: v0.101.0, v0.102.0 Jun 16, 2022
@bep bep modified the milestones: v0.102.0, v0.103.0 Aug 28, 2022
@bep bep modified the milestones: v0.103.0, v0.104.0 Sep 15, 2022
@bep bep modified the milestones: v0.104.0, v0.105.0 Sep 23, 2022
@bep bep modified the milestones: v0.105.0, v0.106.0 Oct 26, 2022
@bep bep modified the milestones: v0.106.0, v0.107.0 Nov 18, 2022
@bep bep modified the milestones: v0.107.0, v0.108.0 Nov 25, 2022
@bep bep modified the milestones: v0.108.0, v0.109.0 Dec 14, 2022
@bep bep modified the milestones: v0.109.0, v0.111.0 Jan 26, 2023
@bep bep modified the milestones: v0.111.0, v0.112.0 Feb 15, 2023
@bep bep modified the milestones: v0.112.0, v0.113.0 Apr 15, 2023
@jmooring
Copy link
Member

Closing.

The .Page.GetTerms method returns the correct results regardless of slashes in term. Example that includes both methods described above:

git clone --single-branch -b hugo-github-issue-4090 https://github.com/jmooring/hugo-testing hugo-github-issue-4090
cd hugo-github-issue-4090
hugo server

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
5 participants