Intra-post anchor links don't work in Safari / Firefox

I’ve been experimenting with anchor links inside of posts (links to content inside of a long post). I have read that you can’t use the ids because they get stripped. I used the name property instead and it works for Chrome but throws a very cryptic error in Safari.

Error: Syntax error, unrecognized expression: [name=anchor-name

It doesn’t give a useful trace so I can’t even tell where it is coming from. Is the anchor routing dealt with by Ember? Is there custom logic for that somewhere?


Example 1 (Live bug)

Try going to this link in Chrome (it works) but in Safari it throws an error and doesn’t work:


Example 2 (Reproduced bug)

works in Chrome, throws errors in safari

Table of contents

Topic 1

The markup for this heading is:

#### <a name="topic-1">Topic 1</a>

Topic 2

The markup for this heading is:

#### <a name="topic-2">Topic 2</a>

TOC Markup

The markup for the table of contents is

### Table of contents
- <a href="#topic-1">Topic 1</a>
- <a href="#topic-2">Topic 2</a>
- <a href="#toc-markup">TOC markup</a>
7 Likes

I can repro this on Firefox v38

2 Likes

Plot like gravy thickens. It appears to not throw any errors in development mode, only in production…

1 Like

Can be minifier related , seen a minifier bug once before

Can you point me to where in the JS this is being handled?

It is here

1 Like

I’m sorry I should have been more specific, I meant where was the name anchor code happening. I dove in and found it in javascripts/discourse/lib/url.js. It looks like there is a missing bracket.

Not sure why that would break only production though…

I’ll submit a PR.

3 Likes

PR submitted

https://github.com/discourse/discourse/pull/3503

4 Likes