How can I backslash into a string?

I have a problem while trying to use this password for postgres db
let pass = “B+=%r”
console.log(pass);

expected output: “B\+=%r”
actual output: “B+=%r”

I’ve tried with String.rawpass or double backslash but still doesn’t work
I’m importing k6/x/sql, k6, k6/http and I’m running it through docker run

Hi @kkk1

Welcome to the community forum :wave:

I understand you are using the xk6-sql extension to connect to a PostgreSQL database. If that is the case, have you seen PostgreSQL connection string special character issues · Issue #21 · grafana/xk6-sql · GitHub? I’m thinking, if this is the PostgreSQL password, you might need to url encode it: B%2B%3D%r. However, I’m unsure, based on the code you shared, why you expect (a password?) to be B\+=%r when you declare B+=%r with console.log(), and why that is causing you issues.

If this doesn’t help, can you share the (sanitized) script you use, and the complete error/output you get? I’m not 100% sure I understand what you need and we’d try to reproduce this with your configuration.

Cheers!

1 Like

let pass = “B\+=%r” **

so what I’m trying to do is to connect to a postgres DB but the pass has a backslash in it and it doesn’t recognize the character, I’ve tried what you said here but still not works, it throws the following error:
level=error msg=“GoError: parse "postgres://myadmin:B%!B(MISSING)%!D(MISSING)%!r(MISSING)@host:port/dbname?sslmode=disable": invalid URL escape "%!r(MISSING)"\n\tat reflect.methodValueCall (native)\n\tat setup (file:///-:37:28(46))\n\tat native\n” hint=“script exception”