namecase icon indicating copy to clipboard operation
namecase copied to clipboard

support for html encoded strings

Open objecttothis opened this issue 10 months ago • 8 comments

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

objecttothis avatar Mar 25 '24 14:03 objecttothis

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;

objecttothis avatar Mar 25 '24 14:03 objecttothis

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

tamtamchik avatar Jul 23 '24 15:07 tamtamchik

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 avatar Jul 23 '24 15:07 objecttothis

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 avatar Jul 29 '24 06:07 objecttothis

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 &

objecttothis avatar Jul 29 '24 07:07 objecttothis

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 avatar Jul 29 '24 09:07 tamtamchik

@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

tamtamchik avatar Aug 06 '24 15:08 tamtamchik

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

objecttothis avatar Aug 06 '24 15:08 objecttothis