Skip to content

Commit

Permalink
Fix missing URL encodings in books' links
Browse files Browse the repository at this point in the history
The URL contain translated texts which are UTF-8, so they need to be
escaped properly.
  • Loading branch information
jnavila committed Jan 11, 2017
1 parent cbe8eb3 commit 6d59156
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def link
link = params[:link]
@book = Book.where(:code => params[:lang], :edition => params[:edition]).first
xref = @book.xrefs.where(:name => link).first
return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{xref.section.slug}##{xref.name}" unless @content
return redirect_to "/book/#{@book.code}/v#{@book.edition}/#{ERB::Util.url_encode(xref.section.slug)}##{xref.name}" unless @content
end

def section
Expand Down
4 changes: 2 additions & 2 deletions app/models/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ def prev_slug
lang = self.book.code
prev_number = self.number - 1
if section = self.sections.where(:number => prev_number).first
return "/book/#{lang}/#{ERB::Util.url_encode(section.slug)}"
return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
else
# find previous chapter
if ch = self.chapter.prev
if section = ch.last_section
return "/book/#{lang}/#{ERB::Util.url_encode(section.slug)}"
return "/book/#{lang}/v#{self.book.edition}/#{ERB::Util.url_encode(section.slug)}"
end
end
end
Expand Down

0 comments on commit 6d59156

Please sign in to comment.