Skip to content
← Back to Community
replaceAll not working ( I think so )
Profile icon
RixTheTyrunt

I made Ifcurs replace all %20 thingies with + like a real browser. But, sadly, the system does not/can't ( however you say ) replace those + as %20, and then decode them again into normal spaces. Can somebody explain what did I mess with my code?

Answered by ch1ck3n [earned 5 cycles]
View Answer
Voters
Profile icon
RixTheTyrunt
Comments
hotnewtop
Profile icon
ch1ck3n

with + like a real browser.

Here is a quick overview on UTF-8
You are probably using chrome. You are probably thinking that this:
image

is correct syntax for UTF-8. But you are 50% wrong. %20 means space in UTF8 so when your browser reads the GET parameters it will just read exactly what you searched in the input.

For example:
https://ch1ck3n.com/?poopy=pee pee
It replaces the space with %20

Profile icon
MrVoo

@ch1ck3n
This is kinda random but h u h ch1ck3n.com is blocked on my school thingy

Profile icon
RixTheTyrunt

Maybe yeah, I don't need to add those plus thingies ( When you add Ifcurs as a "browser engine", Chrome replaces those %20 with +, and the support with them is not added. )

Profile icon
ch1ck3n

@MrVoo
not my problem

Profile icon
MrVoo

@ch1ck3n
I know...?

Profile icon
Coder100

Hi, instead of using replaceAll, try using replace:

console.log("xd%20lol%20xd".replace(/%20/g, "+"));

do take note of the g flag, that makes it so replace tries to match as many times as possible. Without it, it will only match the first one.

Profile icon
ch1ck3n

it has to be .replaceAll(" ", "+"); (with the space)

Profile icon
ch1ck3n

@ch1ck3n
ALSO YOU DONT EVEN HAVE TO DO ANYTHING TO FIX IT

it's all fine

Profile icon
6w6

encodeURIComponent() encodes the % signs in %20, so encodeURIComponent('a%20a') returns 'a%2520a'. Instead of encodeURIComponent(search).replaceAll("%20", "+"), use encodeURIComponent(search).replaceAll("%2520", "+")

Profile icon
RixTheTyrunt

In which line?

Profile icon
6w6

@RixTheTyrunt
nevermind, encodeURIComponent() doesnt encode spaces, check
@ch1ck3n
's reply