Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remote uniqueness validation because of double slash #532

Closed
wants to merge 1 commit into from

Conversation

besi
Copy link

@besi besi commented Apr 30, 2013

This fixes an issue I had:

Started GET "/uniqueness?case_sensitive=true&user%5Bemail%5D=beat.besmer%40gmail.com&_=1367362834432" for 127.0.0.1 at 2013-05-01 01:00:45 +0200

ActionController::RoutingError (No route matches [GET] "/uniqueness"):

The problem was that the url would contain two slashes // (JS Console)

JSCONSOLE> ClientSideValidations.remote_validators_url_for('uniqueness')
"//localhost:3000//validators/uniqueness"

Also see http://stackoverflow.com/questions/15903572/actioncontrollerroutingerror-no-route-matches-get-uniqueness

This fixes an issue I had:

    Started GET "/uniqueness?case_sensitive=true&user%5Bemail%5D=beat.besmer%40gmail.com&_=1367362834432" for 127.0.0.1 at 2013-05-01 01:00:45 +0200

    ActionController::RoutingError (No route matches [GET] "/uniqueness"):

The problem was that the url would contain two slashes `//` (JS Console)

    JSCONSOLE> ClientSideValidations.remote_validators_url_for('uniqueness')
    "//localhost:3000//validators/uniqueness"

Also see <http://stackoverflow.com/questions/15903572/actioncontrollerroutingerror-no-route-matches-get-uniqueness>
@bcardarella
Copy link
Contributor

I think this just fixes the single usecase. If the url being used ends in a slash then you end up with a double slash issue.

Instead there needs to be a way to normalize the url to ensure both cases are covered

@besi
Copy link
Author

besi commented Apr 30, 2013

It is true that it did fix the problem in my case. Since I ran into the issue using the gem out-of-the box, I am wondering if I am not using the gem correctly. So having a ClientSideValidations.remote_validators_prefix would also fix the problem I suppose?

I am not sure if the prefix should result in:

  • either this//localhost/prefixvalidators/uniqueness/
  • or this //localhost/prefix/validators/uniquenss

Could you maybe clarify this. I guess that using an array and then joining the entries would also solve the problem.

['a', 'b', 'c'].join('/');
// Result: a/b/c

@ddarren
Copy link

ddarren commented May 2, 2013

So I was having this issue with the double slashes but it was because ClientSideValidations.remote_validators_prefix was blank instead of null in the below code. So '/' + "" + '/' equals double slashes.

    if (ClientSideValidations.remote_validators_prefix != null) {
      return "//" + window.location.host + "/" + ClientSideValidations.remote_validators_prefix + "/validators/" + validator;
    } else {
      return "//" + window.location.host + "/validators/" + validator;
    }

I fixed it by simply assigning it null in one of my own JavaScript files:

ClientSideValidations.remote_validators_prefix = null

@Dinuz
Copy link

Dinuz commented May 8, 2013

What @ddarren did works perfectly.
I suggest instead of leaving the user to set a ClientSideValidations.remote_validators_prefix = null in a js file, why not checking directly in the code, with something like the following:

window.ClientSideValidations.remote_validators_url_for = function(validator) {
    if (ClientSideValidations.remote_validators_prefix === '') {
        ClientSideValidations.remote_validators_prefix = null;
    }
    if (ClientSideValidations.remote_validators_prefix != null) {
        return "//" + window.location.host + "/" + ClientSideValidations.remote_validators_prefix + "/validators/" +  validator;
    } else {
       return "//" + window.location.host + "/validators/" + validator;
    }
 };

Apparently the remote_validators_prefix is a blank string using a localhost, the previous code just check if it is blank, and in that case automatically set it to null (this I also think solve all the other issue).

What do you think @bcardarella ?

Best
Dinuz

@Dinuz
Copy link

Dinuz commented May 30, 2013

@bcardarella what do you think?

@arr-ee
Copy link
Contributor

arr-ee commented May 30, 2013

Isn’t this a dupe of #513?

@knewter
Copy link

knewter commented Jun 20, 2013

So CoffeeScript is supposed to compile the "?" existential operator down to a null or undefined check, but it's just doing null. Sounds like a bug in coffeescript tbh (I looked into this myself a bit).

At any rate, a full null or undefined check is the appropriate solution, here:

  if ClientSideValidations.remote_validators_prefix?  

@tagliala tagliala closed this Jan 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants