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

clarification on replace functionality broken in 4 and 4.1 #2072

Closed
sivam93 opened this issue Jul 24, 2019 · 6 comments
Closed

clarification on replace functionality broken in 4 and 4.1 #2072

sivam93 opened this issue Jul 24, 2019 · 6 comments

Comments

@sivam93
Copy link

sivam93 commented Jul 24, 2019

hi ,
Can you help me out with the same problem.
Console.log prints single slach() in REPL for the below code

var user="DOMAIN\USERNAME"

console output:DOMAIN\USERNAME.

I am Trying to the user to connect to mssqlserver data base using mssql package.

After assigning the user, and when tried to print the config getting the below output
Code:
var config = {
server: 'DEV',
user: 'DOMAIN\\USERNAME',
password: 'XXXX',
database: 'TEMP'
}

NODE REPL OUTPUT:
{ server: 'DEV',
user: 'DOMAIN\\USERNAME',
password: 'XXX',
database: 'TEMP' }

Seems to be the same issue but because of this not able to connect to the db, getting error: ConnectionError: Login failed for user

@vsemozhetbyt
Copy link

vsemozhetbyt commented Jul 24, 2019

Try 'DOMAIN\\USERNAME' - backslash needs escaping.

@Trott Trott transferred this issue from nodejs/node Jul 24, 2019
@sivam93
Copy link
Author

sivam93 commented Jul 24, 2019

Tried with 'DOMAIN\\USERNAME' .
The REPL Output goes like

{ server: 'DEV',
user: 'DOMAIN\\USERNAME',
password: 'XXX',
database: 'TEMP' }

But assigning the user to a variable ad printing the variable alone gives the output like below
var value = 'DOMAIN\\USERNAME';

Output : 'DOMAIN\USERNAME',

@Hakerh400
Copy link

Hakerh400 commented Jul 24, 2019

Duplicate of nodejs/node#25812

When called with a string, console.log prints the literal string, character by character, so variable user actually contains exactly one slash (in the source code it must be of course escaped with another extra slash) and thus only one slash is printed. That is expected.

When called with an object, console.log calls util.inspect internally and util.inspect formats all strings so that they represent valid JavaScript strings that can be copy-pasted into the source code. In other words, it surrounds strings with ' characters and escapes all characters that need to be escaped in order to represent valid JavaScript source string.

These two different outputs actually represent the same string. Simpler example:

console.log('a\\b');
console.log(['a\\b']);

Output:

a\b
[ 'a\\b' ]

Explanation: the first line of the source code calls console.log by passing string a\b (backslash is escaped using another backslash so there are two backslashes, but the length of the string is only 3 characters). The first line of the output is a\b, which is literal representation of the beforementioned string. The second line of the source code calls console.log by passing an array (arrays are objects), so console.log calls util.inspect, which then formats the array and all its contant, so the representation of the string a\b now becomes 'a\\b', but it is the same string.

Seems to be the same issue but because of this not able to connect to the db, getting error: ConnectionError: Login failed for user

There is an error somewhere else in your script.

@sivam93
Copy link
Author

sivam93 commented Jul 25, 2019

thanks for the explanation on console.log.
But the problem lies around the config object we are setting and it taking the double slash(\\).
the module mssql replies back with the below error:

{ ConnectionError: Login failed for user 'DOMAIN\USERNAME'.
code: 'ELOGIN',
originalError:
{ ConnectionError: Login failed for user 'DOMAIN\\USERNAME'.
message: 'Login failed for user \'DOMAIN\\USERNAME\'.',
code: 'ELOGIN' },
name: 'ConnectionError' }
{ ConnectionError: Connection is closed.

If u see the same log prints two different user name, with two different slashes.
so there is a confusion because the same username password works well in python

@PoojaDurgad
Copy link

@sivam93 , is this issue resolved?

@gireeshpunathil
Copy link
Member

inactive, closing

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

No branches or pull requests

5 participants