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

2.0.0 #3

Merged
merged 5 commits into from
Dec 1, 2021
Merged

2.0.0 #3

merged 5 commits into from
Dec 1, 2021

Conversation

Nathanael-Shermett
Copy link
Contributor

@Nathanael-Shermett Nathanael-Shermett commented Nov 30, 2021

Hello,

I have implemented a number of useful (but backwards-incompatible) fixes and improvements. They are included in the changelog. They are also listed (with brief explanations) below.

Ensure generated URLs are properly formatted (via rawurlencode())

Before this change, generated URLs were technically incorrect if a tracking number had spaces in it. Browsers can typically correct for this by encoding the URL's special characters under the hood, but A) not all browsers do this, and B) any programmatic URL verification (e.g. when using Symfony's UrlType field) would fail.

I opted for rawurlencode() instead of urlencode() because some websites (e.g. DHL's tracking website) interpret plus signs (+) literally.

Sort regular expressions by specificity to decrease likelihood of partial matches when using LinkifyTracking::linkify().

If two patterns exist—ABC and ABCABC—the first pattern would previously be matched earlier, resulting in the latter not being found. Note that I only loosely improved this—I suspect there is still overlap, especially when you consider that carriers can have multiple patterns. I spent about two seconds looking at it and then moved on.

Prevent double linkification when using LinkifyTracking::linkify().

Similar to the previous issue, if one tracking number was linkified but then a subsequent pattern still matched it, the links would be created twice. Now, each replacement is added to a "linkification queue" that stores the replacements that need to be made. To prevent duplication, each match is temporarily replaced with %s. Once all matches have been made, the replacement values stored in the linkification queue are used to finalize the result.

Update DHL tracking number patterns based on information available here. Due to ambiguity, some patterns are intentionally broad.

Title says all. Some could probably be improved to reduce redundancy, but that's a job for another day. Also, I think DHL tracks different types of shipments via different URLs, so we should look into that too.

...

Future changes should probably include adding some tests, adding more specific type hints/annotations, fixing pattern specificity, fixing pattern redundancy, and fixing DHL tracking URLs since I believe they have multiple. We should probably add a minimum PHP requirement to Composer as well. I did none of these things.

Let me know if you have any questions.

@philipnewcomer philipnewcomer merged commit 7b9e022 into philipnewcomer:master Dec 1, 2021
@philipnewcomer
Copy link
Owner

Thank you very much @Nathanael-Shermett for the fixes and improvements, and for the excellent documentation. This is now released as 2.0.0.

I agree that the items you pointed out as future changes are things that should be done. I'll create issues for those.

Thanks again!

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

Successfully merging this pull request may close these issues.

None yet

2 participants