-
Notifications
You must be signed in to change notification settings - Fork 285
Open
Description
For example:
DATABASE_URL='mongodb://[2605:340:c0ff:eeab:be::a25a]:27017/myDatabase' npx prisma db pushResults
Error: P1013
The provided database string is invalid. An invalid argument was provided: address "[2605:340:c0ff:eeab:be::a25a]:27017" contains more than one unescaped ':' in database URL. Please refer to the documentation in https://www.prisma.io/docs/reference/database-reference/connection-urls for constructing a correct connection string. In some cases, certain characters must be escaped. Please check the string for any illegal characters.
And the buggy code is
prisma-engines/libs/mongodb-client/src/lib.rs
Lines 140 to 185 in 46b8397
| let mut parts = address.split(':'); | |
| let hostname = match parts.next() { | |
| Some(part) => { | |
| if part.is_empty() { | |
| return Err(ErrorKind::invalid_argument(format!( | |
| "invalid server address: \"{address}\"; hostname cannot be empty" | |
| )) | |
| .into()); | |
| } | |
| part | |
| } | |
| None => { | |
| return Err( | |
| ErrorKind::invalid_argument(format!("invalid server address: \"{address}\"")).into(), | |
| ); | |
| } | |
| }; | |
| let port = match parts.next() { | |
| Some(part) => { | |
| let port = u16::from_str(part).map_err(|_| { | |
| ErrorKind::invalid_argument(format!( | |
| "port must be valid 16-bit unsigned integer, instead got: {part}" | |
| )) | |
| })?; | |
| if port == 0 { | |
| return Err(ErrorKind::invalid_argument(format!( | |
| "invalid server address: \"{address}\"; port must be non-zero" | |
| )) | |
| .into()); | |
| } | |
| if parts.next().is_some() { | |
| return Err(ErrorKind::invalid_argument(format!( | |
| "address \"{address}\" contains more than one unescaped ':'" | |
| )) | |
| .into()); | |
| } | |
| Some(port) | |
| } | |
| None => None, | |
| }; | |
| Ok((hostname.to_lowercase(), port)) |
which just split the hostname by :... and definitely wrong for IPv6 address.
Metadata
Metadata
Assignees
Labels
No labels