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

stringify adds leading newline #6

Closed
petemill opened this issue Nov 15, 2015 · 2 comments
Closed

stringify adds leading newline #6

petemill opened this issue Nov 15, 2015 · 2 comments

Comments

@petemill
Copy link
Contributor

.parse cannot parse the output of .stringify as it outputs with a leading newline.

Here is a reproducible case:

let sshConfig = require('ssh-config')
let config = sshConfig.parse('');
config.append({ Host: '*', IdentifyFile: '~/.ssh/all' });
let output = sshConfig.stringify(config);

This produces an output with a leading newline. If we then try and parse that output with .parse, we get a corrupted object (which is probably another issue). If we remove the newline manually, .parse works correctly.

I'm thinking the issue is with .stringify

@petemill
Copy link
Contributor Author

If this fix could be merged and published to npm @dotnil , that would be great. Thanks

@cyjake
Copy link
Owner

cyjake commented Nov 17, 2015

@petemill I tried to reproduce the other issue you mentioned with the code below but with no luck.

var obj = sshConfig.parse('')
obj.append({ Host: '*', IdentifyFile: '~/.ssh/all' })
console.log(sshConfig.parse(sshConfig.stringify(obj)))
// { '0': { Host: '*', IdentifyFile: '~/.ssh/all' } }

Theoretically, an leading newline in the text being fed to sshConfig.parse shouldn't cause any issue because the text will be trimmed first. see https://github.com/dotnil/ssh-config/blob/master/index.js#L168

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

2 participants