Always redirect user to downcase version of tags on UTF-8 encoding

This commit is contained in:
Braulio Martinez 2013-04-03 21:58:52 -03:00
parent 06d67bf854
commit c651cbab78
6 changed files with 47 additions and 2 deletions

View file

@ -104,7 +104,8 @@ $(function() {
textFormatter.hashtagify = function hashtagify(text){
var utf8WordCharcters =/(\s|^|>)#([\u0080-\uFFFF|\w|-]+|<3)/g
return text.replace(utf8WordCharcters, function(hashtag, preceeder, tagText) {
return preceeder + "<a href='/tags/" + tagText + "' class='tag'>#" + tagText + "</a>"
return preceeder + "<a href='/tags/" + tagText.toLowerCase() +
"' class='tag'>#" + tagText + "</a>"
})
};

View file

@ -77,7 +77,7 @@ app.Router = Backbone.Router.extend({
if(name) {
var followedTagsAction = new app.views.TagFollowingAction(
{tagText: decodeURIComponent(name)}
{tagText: decodeURIComponent(name).toLowerCase()}
);
$("#author_info").prepend(followedTagsAction.render().el)
}

View file

@ -30,6 +30,8 @@ class TagsController < ApplicationController
end
def show
redirect_to(:action => :show, :name => downcased_tag_name) && return if tag_has_capitals?
if user_signed_in?
gon.tagFollowings = tags
end
@ -45,6 +47,15 @@ class TagsController < ApplicationController
TagFollowing.user_is_following?(current_user, params[:name])
end
def tag_has_capitals?
mb_tag = params[:name].mb_chars
mb_tag.downcase != mb_tag
end
def downcased_tag_name
params[:name].mb_chars.downcase.to_s
end
def prep_tags_for_javascript
@tags.map! do |tag|
{ :name => ("#" + tag.name) }

View file

@ -36,6 +36,17 @@ describe TagsController do
end
describe '#show' do
context 'tag with capital letters' do
before do
sign_in :user, alice
end
it 'redirect to the downcase tag uri' do
get :show, :name => 'DiasporaRocks!'
response.should redirect_to(:action => :show, :name => 'diasporarocks!')
end
end
context 'signed in' do
before do
sign_in :user, alice

View file

@ -214,6 +214,12 @@ describe("app.helpers.textFormatter", function(){
expect(wrapper.find("h1").length).toBe(0)
expect(wrapper.find("a[href='/tags/parties']").text()).toContain("#parties")
})
it("and the resultant link has the tags name downcased", function(){
var formattedText = this.formatter.hashtagify("#PARTIES, I love")
expect(formattedText).toContain("/tags/parties")
})
})
})

View file

@ -15,5 +15,21 @@ describe('app.Router', function () {
expect(followed_tags).toHaveBeenCalled();
expect(tag_following_action).toHaveBeenCalledWith({tagText: 'օբյեկտիվ'});
});
it('navigates to the downcase version of the corresponding tag', function () {
var followed_tags = spyOn(app.router, 'followed_tags').andCallThrough();
var tag_following_action = spyOn(app.views, 'TagFollowingAction').andCallFake(function(data) {
return {render: function() { return {el: ""}}};
});
spyOn(window.history, 'pushState').andCallFake(function (data, title, url) {
var route = app.router._routeToRegExp("tags/:name");
var args = app.router._extractParameters(route, url.replace(/^\//, ""));
app.router.followed_tags(args[0]);
});
window.preloads = {tagFollowings: []};
app.router.navigate('/tags/'+encodeURIComponent('SomethingWithCapitalLetters'));
expect(followed_tags).toHaveBeenCalled();
expect(tag_following_action).toHaveBeenCalledWith({tagText: 'somethingwithcapitalletters'});
});
});
});