question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URL's with # not being written correctly

See original GitHub issue

Hi,

Java 1.8u5 b13. Thymeleaf 2.1.3

I have the following defined in a template:

<a th:href="@{${resetTokenLink}(r=${token})}"><span th:text="${resetTokenLink}">blah</span></a>

I’m passing into my Context, the following:

context.setVariable("resetTokenLink", getDomain() + '/' + resetTokenLink);
context.setVariable("token", token);

getDomain() returns this:

https://www.domain.com

and resetTokenLink variable is defined as:

#/resetToken

Inside the Context (when I observe with a breakpoint), I’m seeing this:

resetTokenLink=https://www.domain.com/#/resetToken
token=kjsk2j3k23

I’m expecting this (URL) to be rendered in the template:

https://www.domain.com/#/resetToken?r=kjsk2j3k23

Instead, I’m getting this:

<a shape="rect" href="https://www.domain.com/?r=kjsk2j3k23#/resetToken"><span>https://www.domain.com/#/resetToken</span></a>

Notice how the “r” comes before the “#” and the URL is malformed.

Perhaps a bug?

-=david=-

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
smazianocommented, Oct 10, 2020

Just in case somebody hits this problem: just build your url and pass it to the template: <a th:href="${resetUrl}">link</a>

This should work fine.

0reactions
dharrigancommented, Aug 7, 2014

Hi,

Thank you Daniel for the consideration of this issue. I understand where you are coming from and it seems the best approach 😃

Thanks again for a great framework and tools! 😃

-=david=-

On 6 August 2014 20:30, Daniel Fernández notifications@github.com wrote:

After some research, I’ve decided to not create a specific syntax for parameters in URI fragment identifiers (as the ones you have in your AngularJS URLs).

The reason is, each client-side framework can do basically whatever it wants with what is specified at the URI fragment identifiers (#…), and the fact that AngularJS uses a query string almost equal in syntax to that of the main part of the URI can be considered a mere syntactic coincidence. The only real syntactic restriction that should be applied to fragment identifiers is that they are correctly escaped (some characters are not allowed in that part of the URI).

So IMO there is no real point in creating thymeleaf general link syntax artifacts for these AngularJS-specific query strings.

BUT what we can offer is some generic tools that ease the work of the developer regarding the manual creation of these URLs (e.g. using literal substutitions |…|). So we just added a new #uris expression utility object (see #305 https://github.com/thymeleaf/thymeleaf/issues/305) based on my new Unbescape http://www.unbescape.org library that can be used for escaping diverse parts of the URI/URLs: paths, path segments, query parameters AND fragment identifiers.

I’m therefore closing this in favour of #305 https://github.com/thymeleaf/thymeleaf/issues/305, which is already implemented and available in 2.1.4-SNAPSHOT.

— Reply to this email directly or view it on GitHub https://github.com/thymeleaf/thymeleaf/issues/289#issuecomment-51392662.

I prefer encrypted and signed messages. KeyID: B20A22F9 Fingerprint: 110A F423 3647 54E2 880F ADAD 1C52 85BF B20A 22F9

“It is not usually until you’ve built and used a version of the program that you understand the issues well enough to get the design right.” - Rob Pike, Brian Kernighan.

No trees were harmed in the sending of this message, however, a number of electrons were inconvenienced.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Fix URL Problems- 6 Effective Techniques - Appsero
The URL will not work if the page doesn't exist. Sometimes, a correct URL will not work because the host deleted it or...
Read more >
How to Troubleshoot an Error in a URL - Lifewire
While there are a number of reasons this might happen, often times the URL is simply incorrect. If there's a problem with a...
Read more >
3 Common URL Problems and How to Fix Them - SEO.com
Problem #1: Non-www and www Versions of Site URLs. If your site has a non-www and www version of all your URLs, you're...
Read more >
How to Format URLs in Text - Quick and Dirty Tips ™
Today's topic is how to treat URLs when you have to use them in text. Web addresses are strange beasts; they seem more...
Read more >
The Complete Guide on Structuring Your URLs Correctly
The recommended character length is listed at no longer than 2,083 characters max — and this is a generous number. Ideally, you really...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found