Links without sub-folder path in embedded comments (Continue Discussion and user links)

I’ve just found a bug with combination of embedded comments and sub-folder installation:
‘Continue Discussion’ button and user links does not respect subfolder path.
But ‘Start Discussion’ button does respect subfolder path.
So I can only post once on embedded thread.

Here is the example: http://nsr24.com/football/game/705041
Discourse installed into: http://nsr24.com/social/en/
‘Start Discussion’ url is http://nsr24.com/social/en/t/bournemouth-west-ham-united-new-sports-rating/13
‘Continue Discussion’ url is just /t/bournemouth-west-ham-united-new-sports-rating/13

Discourse Version v1.5.0.beta8 +11 (Docker + subfolder official guide)

A quick and dirty work-around I can come up with is the following:
add this javascript to Discourse embedded code so the full Discourse code will be:

DiscourseEmbed = { discourseUrl: 'http://nsr24.com/social/en/',
                   discourseEmbedUrl: window.location.href };

(function() {
    var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
    d.src = DiscourseEmbed.discourseUrl + 'javascripts/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);

    // Temporary work around
    setTimeout(function () {
        $('#discourse-embed-frame').contents().find("a").each(function () {
            var value = $(this).attr('href');
            if (!value.startsWith('http')) {
                $(this).attr('href', 'http://nsr24.com/social/en' + value);
            }
        })
    }, 3000);
})();

Hope this help later in debugging this problem.

I think this commit should fix you up:

https://github.com/discourse/discourse/commit/1f8586168bc37d04ebca7653f4d672f600bb0d97

3 Likes

Thank you very much!
I apply this patch in my installation, and during application figured out two more places with similar problems:
You forget to fix /users/ links at app/views/embed/comments.html.erb lines 19 and 23

1 Like

I created a Pull Request, it should completely fix this issue.
https://github.com/discourse/discourse/pull/3958

3 Likes

Merged it in, thanks!

1 Like