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

Upgrade PHPUnit to 10.x. Fix Stream conformance #190

Merged
merged 7 commits into from
Sep 10, 2024

Conversation

gsteel
Copy link
Member

@gsteel gsteel commented Aug 1, 2024

Q A
QA yes

@gsteel gsteel added this to the 3.4.0 milestone Aug 1, 2024
@gsteel gsteel marked this pull request as draft August 1, 2024 18:22
@gsteel
Copy link
Member Author

gsteel commented Aug 1, 2024

This uses 1.x-dev of php-http/psr7-integration-tests in order to install PHPUnit 10.

There's no release there yet: php-http/psr7-integration-tests#76

Some failing tests need attention…

@gsteel gsteel mentioned this pull request Sep 4, 2024
@froschdesign
Copy link
Member

@gsteel
Copy link
Member Author

gsteel commented Sep 4, 2024

So we can't upgrade to PHPUnit 10 without first resolving BC issues around numeric header names, and we won't be able to support PHP 8.4 without upgrading to PHPUnit 10.

This patch is a BC break (probably) because it casts header names to string prior to validation on the assumption that numeric keys have already been cast to int by PHP.

Paging @laminas/technical-steering-committee for input…

Do we need to release a major here?

@gsteel gsteel requested a review from weierophinney September 4, 2024 13:26
@internalsystemerror
Copy link
Member

My thoughts are, BC break = Major version bump. What would be the burden/implications from this?

@gsteel gsteel marked this pull request as ready for review September 4, 2024 13:29
@Xerkus
Copy link
Member

Xerkus commented Sep 4, 2024

Can you elaborate? Numeric headers can not be handled by the library interface and it can not be resolved.
See #159

Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
@weierophinney
Copy link
Member

Agreed with @Xerkus - header names cannot be purely numeric (and this not integers). If anything, this feels like resolving a potential error for users, and not introducing a break.

@gsteel
Copy link
Member Author

gsteel commented Sep 4, 2024

It appears to me that tests no longer pass with the previous behaviour of throwing an exception for integer header names when creating the request from globals.

To get the integration tests to pass, I've cast numerics to string in the appropriate place, but this is the BC break - currently, users expect integer header names to be exceptional and this patch makes them valid as per RFC whatever.

It doesn't affect the existing issue that withHeader('123') will yield int 123 from getHeaders

@gsteel
Copy link
Member Author

gsteel commented Sep 4, 2024

Agreed with @Xerkus - header names cannot be purely numeric (and this not integers). If anything, this feels like resolving a potential error for users, and not introducing a break.

@weierophinney OK - maybe I'm a bit confused here - I thought that numeric header names were valid according to RFC 7230 ??

@Xerkus
Copy link
Member

Xerkus commented Sep 4, 2024

Please see the issue I linked and issues it refers to. We can not allow numeric headers.

@Xerkus
Copy link
Member

Xerkus commented Sep 4, 2024

Please remove type casting for headers from the PR. It hides the issue for the current test implementation.

@gsteel
Copy link
Member Author

gsteel commented Sep 4, 2024

@Xerkus - I'm going to go back to the drawing board on this patch to identify properly where existing test cases are failing.

Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
Signed-off-by: George Steel <george@net-glue.co.uk>
@Xerkus
Copy link
Member

Xerkus commented Sep 4, 2024

@gsteel for context, we filtered out numeric headers from globals when request is created but did not forbid numeric headers in the headers security check because @weierophinney wanted to bring it to PHP-FIG first.

There are numeric headers in the wild from a random http client as evidenced by the original report but we couldn't identify any valid use case for them. Strictly speaking, unregistered headers not prefixed with x- are not RFC conforming. Hence why we should not try to support them just because they fit ABNF.

@gsteel
Copy link
Member Author

gsteel commented Sep 4, 2024

Thanks @Xerkus and @weierophinney

So it turns out that I added some failing tests around this during the upgrade to PHPUnit 10. Whilst I was waiting for the integration tests to get released, I forgot I'd added them and assumed they were new failures.

Generally speaking, I'm just a bit of an idiot!!

Sorry for wasting everyone's time - this should be a straight-forward review now.

@akrabat
Copy link
Member

akrabat commented Sep 4, 2024

Strictly speaking, unregistered headers not prefixed with x- are not RFC conforming.

This is no longer true with RFC9110, where Section 16.3.2.1 states:

Field names ought not be prefixed with "X-"

Numeric only field names are discouraged, but not illegal:

While the field-name syntax is defined to allow any token character, in practice some implementations place limits on the characters they accept in field-names. To be interoperable, new field names SHOULD constrain themselves to alphanumeric characters, "-", and ".", and SHOULD begin with a letter. For example, the underscore ("_") character can be problematic when passed through non-HTTP gateway interfaces (see Section 17.10).

@Xerkus
Copy link
Member

Xerkus commented Sep 4, 2024

This is no longer true with RFC9110, where Section 16.3.2.1 states:

I was not aware we got newer RFC on this. Thank you.

src/Stream.php Show resolved Hide resolved
Signed-off-by: George Steel <george@net-glue.co.uk>
Comment on lines +5 to +6
<code><![CDATA[! $crFound]]></code>
<code><![CDATA[! $crFound]]></code>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this CDATA thrashing in the baseline is due to different xml libraries available when baseline is updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe - I have libxml 2.9.13 locally for PHP 8.1

src/Stream.php Outdated Show resolved Hide resolved
…onditions

Signed-off-by: George Steel <george@net-glue.co.uk>
@gsteel gsteel requested a review from Xerkus September 10, 2024 17:47
@Xerkus Xerkus changed the title Upgrade PHPUnit to 10.x Upgrade PHPUnit to 10.x. Fix Stream conformance Sep 10, 2024
@Xerkus Xerkus added the Bug Something isn't working label Sep 10, 2024
@Xerkus Xerkus merged commit 1f86ae1 into laminas:3.4.x Sep 10, 2024
12 checks passed
@Xerkus
Copy link
Member

Xerkus commented Sep 10, 2024

@gsteel Thank you

@gsteel gsteel deleted the phpunit-10 branch September 10, 2024 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants