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

Attempt to fix issue #141. #192

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Conversation

hktang
Copy link

@hktang hktang commented May 29, 2024

Hi it seems the issue with additional slashes come from the following code:

$pattern = "/(\s|\/)/";

if (!preg_match($pattern, $titleString, $matches)) {
    return StringHelper::mb_ucfirst($titleString);
}

// Here, delimiter could either be whitespace or a slash.
$delimiter = $matches[1];

// Here, the title is split by both whitespate AND a slash.
// If the $delimiter happens to be a slash, then the string will be
// pieced back together by slashes.
$wordArray = preg_split($pattern, $titleString); //explode(" ", $titleString);

Without changing the original code, I propose we walk through the converted string,
and keep the occurrence of a delimiter if they exist in both strings, but replace it
with the original character (a whitespace) if it doesn't exist in the original string.

This should be safe but I don't insist on the implementation. Please let me know
your thoughts!

Also, I added some test cases in the unit test for this function. I hope they are useful.

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

1 participant