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

(SMHassanAlavi) #1

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.


pages with error:

pages without error:

So I think the problem is from the topic controller.

(Rafael dos Santos Silva) #2

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

(SMHassanAlavi) #3

Yes, This is because Persian is RTL language.

in fact the url is like this:



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:


for Persian slug the output was like this:


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:


BUT Persian slug:


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

(Pad Pors) #4

seems related (same error in the admin panel):

(Erick Guan) #5

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

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

(Matt Palmer) #6

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

(SMHassanAlavi) #7

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

(Pad Pors) #8

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:

(Alan Tan) #9

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

Automatic encoding of parsed URL params
(Alan Tan) #10