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

Invalid URL error with database credentials including special characters invalid for URLs #191

Open
2 tasks
karlhorky opened this issue Feb 7, 2023 · 0 comments

Comments

@karlhorky
Copy link
Member

karlhorky commented Feb 7, 2023

If a .env file has been set up with a PGUSERNAME, PGPASSWORD, PGHOST or PGDATABASE which include special characters that are invalid for usage in a URL, the SafeQL configuration value for databaseUrl that we use (which includes interpolation) will cause unusual problems:

(config.rules)['@ts-safeql/check-sql'] = [
'error',
{
connections: [
{
databaseUrl: `postgres://${process.env.PGUSERNAME}:${process.env.PGPASSWORD}@${process.env.PGHOST}:5432/${process.env.PGDATABASE}`,
tagName: 'sql',
fieldTransform: 'camel',
transform: '{type}[]',
},
],
},
];

Running ESLint or Preflight in such a project will lead to error messages such as TypeError [ERR_INVALID_URL]: Invalid URL:

image

We could escape the special characters in these values to avoid these types of errors with the interpolation.

TODOs:

  • research for an official source (eg. official docs) on which characters need to be escaped in a PostgreSQL URL
  • research for an official source (eg. official docs) on how we should escape them. seems like maybe percent-encoding is ok here?
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

1 participant