tamtamchik / namecase

PHP package that converts names into the correct case where it is possible.
https://tamtamchika.net/namecase
MIT License
77 stars 7 forks source link

support for html encoded strings #20

Open objecttothis opened 5 months ago

objecttothis commented 5 months ago

Currently if I pass & through, namecase changes it to &Amp; which breaks decoding. Please add an ignore for html encoded entities. <, >, &amp, ' and "

objecttothis commented 5 months ago

Here is what I'm having to do currently to get around the problem:

        $adjusted_name = str_name_case($input);

        // Use preg_replace_callback to match HTML entities and convert them to lowercase.
        $adjusted_name = preg_replace_callback('/&[a-zA-Z0-9#]+;/', function($matches) {
            return strtolower($matches[0]);
        }, $adjusted_name);

        return $adjusted_name;
tamtamchik commented 1 month ago

I'm sorry for the late fix! @objecttothis but is it possible to ask you to verify the fixed version:

composer require tamtamchik/namecase:3.1.0-beta.0
objecttothis commented 1 month ago

Thank you for this fix. I work on the project which uses this library on Mondays and Tuesdays so I'll make a note to test it on Monday. We are at end of day Tuesday here.

objecttothis commented 1 month ago

I'm sorry for the late fix! @objecttothis but is it possible to ask you to verify the fixed version:

composer require tamtamchik/namecase:3.1.0-beta.0

Just tested 3.1.0-beta.0 and the following image

gets replaced with image

Which is what I would expect, but this image

gets replaced with image

I didn't get this behavior every time, though it was unclear to me exactly which circumstances it was giving the correct output

objecttothis commented 1 month ago

I think my example isn't really clear.

When I submit image

the first time I got image

and that is what I expect to get back. However when I resubmit image

I get image

which is not expected. The difference between the two is that the first requires capitalization of joe. I was able to repeat the result, so it's something to do with the way it's handling Joe & differently than joe &

tamtamchik commented 1 month ago

Thank you for the feedback, @objecttothis; that is why I didn't publish it as a new release. I'll debug and fix the issue ASAP.

tamtamchik commented 1 month ago

@objecttothis, try this one; sorry for being late, I was trying different approaches, but the one you use looks like the most reliable.

composer require tamtamchik/namecase:3.1.0-beta.1
objecttothis commented 1 month ago

Sounds good. I'm out of the office until the 16th but I'll test it then if it's still needed.