Skip to content

Commit

Permalink
Prepare 1.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed May 7, 2023
1 parent 3eb3ec7 commit 6579426
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 47 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All Notable changes to `bakame/http-strucured-fields` will be documented in this file.

## [Next] - TBD
## [1.1.0] - 2023-05-07

### Added

Expand Down Expand Up @@ -332,7 +332,8 @@ All Notable changes to `bakame/http-strucured-fields` will be documented in this

**Initial release!**

[Next]: https://github.com/bakame-php/http-structured-fields/compare/1.0.1...master
[Next]: https://github.com/bakame-php/http-structured-fields/compare/1.1.0...master
[1.1.0]: https://github.com/bakame-php/http-structured-fields/compare/1.0.1...1.1.0
[1.0.1]: https://github.com/bakame-php/http-structured-fields/compare/1.0.0...1.0.1
[1.0.0]: https://github.com/bakame-php/http-structured-fields/compare/0.8.0...1.0.0
[0.8.0]: https://github.com/bakame-php/http-structured-fields/compare/0.7.0...0.8.0
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ build and update HTTP Structured Fields in PHP according to the [RFC8941](https:
Once installed you will be able to do the following:

```php
use Bakame\Http\StructuredFields\InnerList;
use Bakame\Http\StructuredFields\Item;
use Bakame\Http\StructuredFields\OuterList;
use Bakame\Http\StructuredFields\Token;
use Bakame\Http\StructuredFields\{InnerList, Item, OuterList, Token};

//1 - parsing an Accept Header
$headerValue = 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8';
Expand Down
6 changes: 3 additions & 3 deletions src/InnerList.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ final class InnerList implements MemberList, ParameterAccess
*/
private function __construct(iterable $members, private readonly Parameters $parameters)
{
$this->members = array_map(self::filterMember(...), array_values([...$members]));
$this->members = array_map($this->filterMember(...), array_values([...$members]));
}

/**
* @param SfItemInput $member
*
* @return SfItem
*/
private static function filterMember(mixed $member): object
private function filterMember(mixed $member): object
{
return match (true) {
$member instanceof ValueAccess && $member instanceof ParameterAccess => $member,
Expand Down Expand Up @@ -285,7 +285,7 @@ public function remove(string|int ...$keys): static

return match (true) {
[] === $indices => $this,
$max === count($indices) => self::new(),
count($indices) === $max => self::new(),
default => new self(array_filter(
$this->members,
fn (int $key): bool => !in_array($key, $indices, true),
Expand Down
4 changes: 2 additions & 2 deletions src/OuterList.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ final class OuterList implements MemberList
*/
private function __construct(iterable|StructuredField|Token|ByteSequence|DateTimeInterface|string|int|float|bool ...$members)
{
$this->members = array_map(self::filterMember(...), array_values([...$members]));
$this->members = array_map($this->filterMember(...), array_values([...$members]));
}

/**
* @param SfMember|SfMemberInput $member
*
* @return SfMember
*/
private static function filterMember(mixed $member): object
private function filterMember(mixed $member): object
{
return match (true) {
$member instanceof ParameterAccess && ($member instanceof MemberList || $member instanceof ValueAccess) => $member,
Expand Down
71 changes: 35 additions & 36 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ final class Parser implements DictionaryParser, InnerListParser, ItemParser, Lis

public function parseValue(Stringable|string $httpValue): ByteSequence|Token|DateTimeImmutable|string|int|float|bool
{
$valueString = trim((string) $httpValue, ' ');
if ('' === $valueString || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $valueString)) {
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item value contains invalid characters.');
$remainder = trim((string) $httpValue, ' ');
if ('' === $remainder || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $remainder)) {
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item value contains invalid characters.");
}

[$value, $offset] = self::extractValue($valueString);
if ('' !== substr($valueString, $offset)) {
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item value contains invalid characters.');
[$value, $offset] = self::extractValue($remainder);
if ('' !== substr($remainder, $offset)) {
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item value contains invalid characters.");
}

return $value;
Expand All @@ -64,15 +64,15 @@ public function parseValue(Stringable|string $httpValue): ByteSequence|Token|Dat
*/
public function parseItem(Stringable|string $httpValue): array
{
$itemString = trim((string) $httpValue, ' ');
if ('' === $itemString || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $itemString)) {
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
$remainder = trim((string) $httpValue, ' ');
if ('' === $remainder || 1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $remainder)) {
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item contains invalid characters.");
}

[$value, $offset] = self::extractValue($itemString);
$remainder = substr($itemString, $offset);
[$value, $offset] = self::extractValue($remainder);
$remainder = substr($remainder, $offset);
if ('' !== $remainder && !str_contains($remainder, ';')) {
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for an item contains invalid characters.');
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for an item contains invalid characters.");
}

return [$value, $this->parseParameters($remainder)];
Expand All @@ -89,10 +89,10 @@ public function parseItem(Stringable|string $httpValue): array
*/
public function parseParameters(Stringable|string $httpValue): array
{
$parameterString = trim((string) $httpValue);
[$parameters, $offset] = self::extractParametersValues($parameterString);
if (strlen($parameterString) !== $offset) {
throw new SyntaxError('The HTTP textual representation "'.$httpValue.'" for Parameters contains invalid characters.');
$remainder = trim((string) $httpValue);
[$parameters, $offset] = self::extractParametersValues($remainder);
if (strlen($remainder) !== $offset) {
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for Parameters contains invalid characters.");
}

return $parameters;
Expand Down Expand Up @@ -170,23 +170,23 @@ public function parseInnerList(Stringable|string $httpValue): array
*
* @see https://tools.ietf.org/html/rfc7230#section-3.2.3
*/
private static function removeCommaSeparatedWhiteSpaces(string $httpValue, int $offset): string
private static function removeCommaSeparatedWhiteSpaces(string $remainder, int $offset): string
{
$httpValue = self::removeOptionalWhiteSpaces(substr($httpValue, $offset));
if ('' === $httpValue) {
return $httpValue;
$remainder = self::removeOptionalWhiteSpaces(substr($remainder, $offset));
if ('' === $remainder) {
return '';
}

if (1 !== preg_match(self::REGEXP_VALID_SPACE, $httpValue, $found)) {
if (1 !== preg_match(self::REGEXP_VALID_SPACE, $remainder, $found)) {
throw new SyntaxError('The HTTP textual representation is missing an excepted comma.');
}

$httpValue = substr($httpValue, strlen($found['space']));
if ('' === $httpValue) {
$remainder = substr($remainder, strlen($found['space']));
if ('' === $remainder) {
throw new SyntaxError('The HTTP textual representation has an unexpected end of line.');
}

return $httpValue;
return $remainder;
}

/**
Expand Down Expand Up @@ -242,11 +242,11 @@ private static function extractInnerList(string $httpValue): array
[$list[], $remainder] = self::extractItem($remainder);

if ('' !== $remainder && !in_array($remainder[0], [' ', ')'], true)) {
throw new SyntaxError("The HTTP textual representation \"$remainder\" for a inner list is using invalid characters.");
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a inner list is using invalid characters.");
}
}

throw new SyntaxError("The HTTP textual representation \"$remainder\" for a inner list has an unexpected end of line.");
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a inner list has an unexpected end of line.");
}

/**
Expand Down Expand Up @@ -372,41 +372,40 @@ private static function extractDate(string $httpValue): array
private static function extractString(string $httpValue): array
{
$offset = 1;
$originalHttpValue = $httpValue;
$httpValue = substr($httpValue, $offset);
$remainder = substr($httpValue, $offset);
$output = '';

while ('' !== $httpValue) {
$char = $httpValue[0];
while ('' !== $remainder) {
$char = $remainder[0];
$offset += 1;

if ('"' === $char) {
return [$output, $offset];
}

if (1 === preg_match(self::REGEXP_INVALID_CHARACTERS, $char)) {
throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
}

$httpValue = substr($httpValue, 1);
$remainder = substr($remainder, 1);

if ('\\' !== $char) {
$output .= $char;
continue;
}

$char = $httpValue[0] ?? '';
$char = $remainder[0] ?? '';
$offset += 1;
$httpValue = substr($httpValue, 1);
$remainder = substr($remainder, 1);

if (!in_array($char, ['"', '\\'], true)) {
throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
}

$output .= $char;
}

throw new SyntaxError("The HTTP textual representation \"$originalHttpValue\" for a String contains an invalid end string.");
throw new SyntaxError("The HTTP textual representation \"$httpValue\" for a String contains an invalid end string.");
}

/**
Expand Down

0 comments on commit 6579426

Please sign in to comment.