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

replace sub-delim \} by \) in regexp #26

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependency Review Action
#
# This Action will scan dependency manifest files that change as part of a Pull Request, surfacing known-vulnerable versions of the packages declared or updated in the PR. Once installed, if the workflow run is marked as required, PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
# Public documentation: https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/about-dependency-review#dependency-review-enforcement
name: 'Dependency Review'
on: [pull_request]

permissions:
contents: read

jobs:
dependency-review:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Repository'
uses: actions/checkout@v3
- name: 'Dependency Review'
uses: actions/dependency-review-action@v2
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,22 +232,22 @@ userinfo:

path:
"Normal" URL path according to RFC3986 section 3.3.
REGEX: (/? | (/[a-zA-Z0-9-\._~%!\$&'\(\}\*\+,;=:@]+)+)
REGEX: (/? | (/[a-zA-Z0-9-\._~%!\$&'\(\)\*\+,;=:@]+)+)

query:
"Normal" URL query according to RFC3986 section 3.4.
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\}\*\+,;=:@]+
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\)\*\+,;=:@]+

user:
This value can be URL encoded.
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\}\*\+,;=]+
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\)\*\+,;=]+

password:
This value can be URL encoded.
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\}\*\+,;=]+
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\)\*\+,;=]+

host:
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\}\*\+,;=]+
REGEX: [a-zA-Z0-9-\._~%!\$&'\(\)\*\+,;=]+

post:
REGEX: [0-9]+
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
{
"name": "nyholm/dsn",
"type": "library",
"description": "Parse your DSN strings in a powerful and flexible way",
"license": "MIT",
"type": "library",
"keywords": [
"dsn",
"parser",
"dsn parser",
"database"
],
"homepage": "http://tnyholm.se",
"license": "MIT",
"authors": [
{
"name": "Tobias Nyholm",
"email": "tobias.nyholm@gmail.com"
}
],
"homepage": "http://tnyholm.se",
"require": {
"php": ">=7.1"
},
"require-dev": {
"symfony/phpunit-bridge": "^5.1"
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
},
"autoload": {
"psr-4": {
"Nyholm\\Dsn\\": "src/"
Expand All @@ -36,5 +31,10 @@
"psr-4": {
"Nyholm\\Dsn\\Test\\": "tests/"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}
29 changes: 23 additions & 6 deletions src/DsnParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class DsnParser
private const FUNCTION_REGEX = '#^([a-zA-Z0-9\+-]+):?\((.*)\)(?:\?(.*))?$#';
private const ARGUMENTS_REGEX = '#([^\s,]+\([^)]+\)(?:\?[^\s,]*)?|[^\s,]+)#';
private const UNRESERVED = 'a-zA-Z0-9-\._~';
private const SUB_DELIMS = '!\$&\'\(\}\*\+,;=';
private const SUB_DELIMS = '!\$&\'\(\)\*\+,;=';

/**
* Parse A DSN thay may contain functions. If no function is present in the
Expand Down Expand Up @@ -52,7 +52,10 @@ public static function parseFunc(string $dsn): DsnFunction
$arguments = $matches[1];
}

return new DsnFunction($functionName, array_map(\Closure::fromCallable([self::class, 'parseArguments']), $arguments), $parameters);
return new DsnFunction(
$functionName,
array_map(\Closure::fromCallable([self::class, 'parseArguments']), $arguments),
$parameters);
}

/**
Expand Down Expand Up @@ -113,7 +116,9 @@ private static function parseArguments(string $dsn)
private static function getDsn(string $dsn): Dsn
{
// Find the scheme if it exists and trim the double slash.
if (!preg_match('#^(?:(?<alt>['.self::UNRESERVED.self::SUB_DELIMS.'%]+:[0-9]+(?:[/?].*)?)|(?<scheme>[a-zA-Z0-9\+-\.]+):(?://)?(?<dsn>.*))$#', $dsn, $matches)) {
if (!preg_match(
'#^(?:(?<alt>['.self::UNRESERVED.self::SUB_DELIMS.'%]+:[0-9]+(?:[/?].*)?)|(?<scheme>[a-zA-Z0-9\+-\.]+):(?://)?(?<dsn>.*))$#',
$dsn, $matches)) {
throw new SyntaxException($dsn, 'A DSN must contain a scheme [a-zA-Z0-9\+-\.]+ and a colon.');
}
$scheme = null;
Expand All @@ -128,7 +133,9 @@ private static function getDsn(string $dsn): Dsn
}

// Parse user info
if (!preg_match('#^(?:(['.self::UNRESERVED.self::SUB_DELIMS.'%]+)?(?::(['.self::UNRESERVED.self::SUB_DELIMS.'%]*))?@)?([^\s@]+)$#', $dsn, $matches)) {
if (!preg_match(
'#^(?:(['.self::UNRESERVED.self::SUB_DELIMS.'%]+)?(?::(['.self::UNRESERVED.self::SUB_DELIMS.'%]*))?@)?([^\s@]+)$#',
$dsn, $matches)) {
throw new SyntaxException($dsn, 'The provided DSN is not valid. Maybe you need to url-encode the user/password?');
}

Expand All @@ -146,12 +153,22 @@ private static function getDsn(string $dsn): Dsn
if ('/' === $matches[3][0]) {
$parts = self::explodeUrl($matches[3], $dsn);

return new Path($scheme, $parts['path'], self::getQuery($parts), $authentication);
return new Path(
$scheme,
$parts['path'],
self::getQuery($parts),
$authentication);
}

$parts = self::explodeUrl('http://'.$matches[3], $dsn);

return new Url($scheme, $parts['host'], $parts['port'] ?? null, $parts['path'] ?? null, self::getQuery($parts), $authentication);
return new Url(
$scheme,
$parts['host'],
$parts['port'] ?? null,
$parts['path'] ?? null,
self::getQuery($parts),
$authentication);
}

/**
Expand Down