EmptyPockets
EmptyPockets

Reputation: 727

Passing in a key results in extra characters in my firebase URL, how do I remove them?

When placing the "key" variable inside of this string, it displays 'simplelogin%3A5' instead of 'simplelogin:5'. Is there a way to just pass in the latter?

  var populateTasks = function(date, key){
    $scope.ref = new Firebase("https://myfirebase.firebaseio.com/users/"+key+"/tasks");   
  };

results in: https://myfirebase.firebaseio.com/users/simplelogin%3A5/tasks I need: https://myfirebase.firebaseio.com/users/simplelogin:5/tasks

Upvotes: 0

Views: 71

Answers (3)

Frank van Puffelen
Frank van Puffelen

Reputation: 599491

Where does the value of key come from? If you get it from a URL, it makes sense that you see %3A.

A : has a special meaning in a URL, so it is escaped. And the URL escape sequence for a : is %3A.

To convert the %3A back to : you simply unescape it like this:

unescape(key)

Or use decodeURIComponent, which in this case accomplishes the same. The best way to decode the value depends on why it was encoded in the first place, hence my initial question.

Upvotes: 1

user3890194
user3890194

Reputation: 65

Have you tried trimming key before concatenating it to the URL?

key = key.trim();

Upvotes: 0

EmptyPockets
EmptyPockets

Reputation: 727

var uri = "//what you need to convert";
var uri_dec = decodeURIComponent(uri);
var res = uri_dec;

Upvotes: 1

Related Questions