Keep special characters in url / path

Hi all.

I have two .md with the following front matters: (repo)

The first contains: (link)

---
title: Test !
url: test!
---

the other: (link)

---
title: Test ?
url: test?
---

As expected, when the site is built, the ! and ? characters are stripped from the url, hence from the directories containing the respective index.html. That leads me to have 2 different posts with the same url/path.

However, I manually edited the public generated directory to have two directories named test! and test? and pushed the whole site to Github (link).

Github seems to have no problem in working with those paths having special characters (link)

After read a lot of similar questions I am confident that this is the expected behavior, however I wonder if that behavior can be disabled or is there any other workaround instead of manually rename generated files.

this are reserved character in URLs

https://tools.ietf.org/html/rfc3986 under 2.2

Hugo tries to build correct URLs!

Thanks @ju52!

What I’d like to know is if there is any way to tell Hugo that I know what I’m doing and I want to encode those special characters instead to indiscriminately strip them.

For me it would be OK if Hugo encode test! as test%21 and test? as test%3F (which are valid parts of URLs) and browse the pages using /test%21/ and test%3F/ respectively.

Update:

I used the following value for the url field:

---
title: Test !
url: test%21
---

which seems to create the directories as I desired. However, as Hugo maps URLs 1:1 over paths this is even worst: while the .Permalink is /test%21/ the document is accesible only through /test%2521/ (Notice that now the % is encoded).

So the only solution seems to have directories named /test!/ but even the filesystems have their own set of reserved characters.

It seems there is no easy solution for this.

---
title: Test !
url: test%21
aliases: ["test!"]
---

works! include the path!

Nice idea! Although I didn’t work for me (at all).

The first issue I found is that I get infinite redirections if I use the urls you provided:

/test! --[301]--> /test%21 => /test! --[301]--> /test%21 ...

Then I decide to use a sightly different disambiguation url:

---
title: Test !
url: test____%21 # <= many underscores to make it obvious
aliases: ["test!"]
---
/test! --[301]--> /test____%21 --> 404

The problem here is that I need to request not test____%21 but test____%2521 in order to get the final page.

However I can go with the initial redirection and use some simpler canonical URL like:

---
url: test-excl
alias: ['test!']
---

The only remaining work is to rename every *-excl URL to *! everytime I render a link.

I think this is enough for my needs now. Thanks a lot @ju52!