When slug generation method is encoded, It redirected many times when we open new tab opens in topic

Continuing the discussion from ERR_TOO_MANY_REDIRECTS After Rebuild:

I found out that the error ERR_TOO_MANY_REDIRECTS after last update was because of non-english character in title. When I changed the slug generation method to none, and created a new topic(that doesn’t include non-english character in slug and url) it opens with no error but that previous topics has still the problem.

PAY ATTENTION to URL:

pages with error:

pages without error:

So I think the problem is from the topic controller.

1 Like

On your first screenshot the slug is after the topic_id, is that normal?

1 Like

Yes, This is because Persian is RTL language.

in fact the url is like this:

http://localhost:3000/t/%D8%A2%DB%8C%D8%A7-%D8%B2%D8%A8%D8%A7%D9%86-%D9%81%D8%A7%D8%B1%D8%B3%DB%8C-%D9%86%D9%82%D8%B4%DB%8C-%D8%AF%D8%B1-%D8%B4%DA%A9%D9%84%E2%80%8C%DA%AF%DB%8C%D8%B1%DB%8C-%D8%AA%D9%81%DA%A9%D8%B1-%D8%A7%D8%AD%D8%B3%D8%A7%D8%B3%DB%8C-%D9%88-%DB%8C%D8%A7-%D8%B9%D9%82%D9%84%D8%A7%D9%86%DB%8C-%D9%85%D8%A7-%D8%AF%D8%A7%D8%B1%D8%AF%D8%9F/4790

UPDATE:

I have done this to check the error in line 661 in definition of slug_do_not_match method:

first check:

puts params[:slug]
puts @topic_view.topic.slug
puts @topic_view.topic.slug != params[:slug]

for English slug the output was like this:

topic
topic
false

for Persian slug the output was like this:

مشکل-پیدا-کردن-ترجمه-ی-خوب
مشکل-پیدا-کردن-ترجمه-ی-خوب
true

and I have changed the checking code like this:

puts params[:slug].length
puts @topic_view.topic.slug.length
puts @topic_view.topic.slug != params[:slug]

and the out put was interesting:

English slug:

6
6
false

BUT Persian slug:

36
66
true

I found out that it may save some whitespace after the name of the Persian slug(because whitespaces aren’t visible in console)

seems related (same error in the admin panel):

Did you try puts @topic_view.topic.slug != params[:slug].strip

And what’s the @topic_view.topic.slug.encoding and params[:slug].encoding?

$20 says params[:slug].encoding is ASCII-8BIT. I think we need to fix this everywhere, as per this topic.

3 Likes

yes and the problem still exist. .strip method won’t solve it.

we had faced this problem in our site, and to solve it temporarily and for short time:

1- we changed the slug generation method in admin panel to none.
2- then we created a temp category, and select all old topics with Persian slug, move them to that category, and bring them back!

this way the slug of all the topics became some simple topic-numbers without any Persian character. there’s a simpler way of using code lines in the link below, that I didn’t try:

2 Likes

@Alavi1412 Can you upgrade to latest? This is fixed after we upgraded to Rails 5.1

4 Likes