-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Fix handling of taxonomy terms containing slashes #4388
Conversation
@bep, I've confirmed the failures with Go 1.9.3, 1.9.4, 1.10rc1, and 1.10rc2. The following will bypass the test cache in Go 1.10:
|
Correction: I'm able to reproduce the anomaly in Go 1.10rc2 without the race detector. |
Fixed the issue. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid, just a couple of minore comments.
@@ -75,6 +75,35 @@ func (filepathBridge) Separator() string { | |||
|
|||
var fpb filepathBridge | |||
|
|||
// segmentReplacer replaces some URI-reserved characters in a path segments. | |||
var segmentReplacer = strings.NewReplacer("/", "-", "#", "-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you replace "-" with "-"? (the same character).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NewReplacer uses "old-new" pairs. This replaces '/' and '#' with '-'.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if there is a ?
character? Is it possible to use a common url encoding here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the tests below. The ?
is removed. URL encoding is beyond the scope of this PR.
var last byte | ||
b := make([]byte, len(s)) | ||
|
||
for i := 0; i < len(s); i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I read this correctly this removes double-slashes. I assume that come from "My // Taxonomy" cases. Which is fine as long as this isn't used in the "general case" (which would break some URLs and make people grumpy). But you should add a test variant for it below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we would replace both slashes with -
using segmentReplacer
(other interesting characters like a space and ?
are replaced by MakePathSanitized
used above), and this loop removes consecutive dashes.
So, My // Taxonomy
would become my-taxonomy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
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. |
@bep, |
@moorereason Let's say that I have a taxonomy called Then the taxonomy is assigned to content files with: With the above Hugo is able to nest a taxonomy under a Section or another Taxonomy. Also here is another use case with the above technique to generate Chronological Blog Archives. As you understand in both use cases the forward slashes are desirable. |
@onedrawingperday, I think it will work as you expect, but I'd be more than happy to test a sample site if you have one available. |
@moorereason Here is a sample repo with Nested Taxonomies for you to test. I have included both of the use cases that I described above. Thanks! |
Add tests with slashes in terms to illuminate failing code paths. Updates gohugoio#4090
MakePathSegment properly sanitizes path segments (like taxonomy terms) with slashes (and pound signs). Updates gohugoio#4090
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
Don't mix casing in the "cat1" taxonomy term test because Hugo doesn't support multiple terms whose lowercase strings collide. Related to gohugoio#4238
MakeSegment will replace slashes in a path segment, so make sure we include tests for that.
Case changed since last git rebase.
More cleanups from rebasing with master.
Thanks, @onedrawingperday. I tested your site with my original PR branch and also rebased with the latest master. In both cases, your test site comes out exactly the same. 👍 |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This PR attempts to resolve #4090. The first commit contains tests that demonstrate the problem.
Special thanks to @tsuereth for his initial work on #4092, which laid the groundwork for this PR.
This PR may fix the title issues in #3577, but I haven't tested it yet.