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

Bug: Url Helper have a bug #3180

Closed
mmrtonmoybd opened this issue Jun 28, 2020 · 0 comments
Closed

Bug: Url Helper have a bug #3180

mmrtonmoybd opened this issue Jun 28, 2020 · 0 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@mmrtonmoybd
Copy link
Contributor

mmrtonmoybd commented Jun 28, 2020

In url helper have a method url_title(). It can makes a slug from string. It also support Unicode. But it not totally support Unicode.
I tried to do a string to slug but codeigniter gives output:
$cname = "মশিউর রহমান";
echo url_title($cname, '-', TRUE);
Output: মশউর-রহমন

Expect: মশিউর-রহমান

I do few changes in system/Helpers/url_helper.php

In before
///////////////////////////////

function url_title(string $str, string $separator = '-', bool $lowercase = false): string
	{
		$q_separator = preg_quote($separator, '#');

		$trans = [
			'&.+?;'                   => '',
			'[^\w\d _-]'              => '',
			'\s+'                     => $separator,
			'(' . $q_separator . ')+' => $separator,
		];

		$str = strip_tags($str);
		foreach ($trans as $key => $val)
		{
			$str = preg_replace('#' . $key . '#iu', $val, $str);
		}

		if ($lowercase === true)
		{
			$str = mb_strtolower($str);
		}

		return trim(trim($str, $separator));
	}
}

/////////////////////////////
I do few changes
In after

function url_title(string $str, string $separator = '-', bool $lowercase = false, string $patran = ''): string
	{
		$q_separator = preg_quote($separator, '#');

		if ($patran != '') {
		  $trans = [
			'&.+?;'                   => '',
			$patran              => '',
			'\s+'                     => $separator,
			'(' . $q_separator . ')+' => $separator,
		];
		} else {
		   $trans = [
			'&.+?;'                   => '',
			'[^\w\d _-]'              => '',
			'\s+'                     => $separator,
			'(' . $q_separator . ')+' => $separator,
		];
		}

		$str = strip_tags($str);
		foreach ($trans as $key => $val)
		{
			$str = preg_replace('#' . $key . '#iu', $val, $str);
		}

		if ($lowercase === true)
		{
			$str = mb_strtolower($str);
		}

		return trim(trim($str, $separator));
	}
} 

////////////////

$cname = "মশিউর রহমান";
url_title($cname, '-', TRUE, '[^a-z0-9\x{0980}-\x{09ff}]');
Output: মশিউর-রহমান
It works and output same as my expected.
I add a pattern option that anyone can replace there string as they want.
I hope the changes will be add next version. If I do any worng. Please comment on this issue.

@mmrtonmoybd mmrtonmoybd added the bug Verified issues on the current code behavior or pull requests that will fix them label Jun 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

1 participant