-1

To keep this simple, I am using Firebase Cloud Functions, and when/if I receive a param that contains a #, it doesn't recognize it.

For example: http://example.net?id=123#456. if I log the id, ill only get 123.

However, if I do something like http://example.net?id=123456, everything will be logged.

How can I include the # sign with the string value for id?

Better Detail:

URL: http://example.com?item=2019+#157&typeOfListing=sold

If I encode the request query

let item = encodeURIComponent(req.query.item);

I will get the following:

2019%20

It is not taking the # with it.

letsCode
  • 2,774
  • 1
  • 13
  • 37

1 Answers1

1

That's because # is a special character in urls (just like /, :, ?, ... are), it's used to denote the fragment part of the url. You need to escape it using encodeURIComponent like so:

let idParam = encodeURIComponent("123#456");
let url = "http://example.net?id=" + idParam;
ibrahim mahrir
  • 31,174
  • 5
  • 48
  • 73