-
Notifications
You must be signed in to change notification settings - Fork 966
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
Titlelize returns empty if text contains no known letters #385
Comments
Thanks for reporting this Adrian. This is not by design; it's a bug. Did you want to send a PR? :)
|
Thanks Mehdi - if I get chance I'll try to have a look! |
Hello, I am unable to reproduce the InvalidOperationException even with the examples given it just returns an empty string. Is this still an issue and if so is returning an empty string the desired behavior? |
I've just updated to v1.34.0 - it no longer throws the exception, but I'm not convinced that returning an empty string is the desired behaviour, personally I would expect it to return the original string if it can't process it? |
I agree, returning an empty string feels like data lose. I think we should always try to save as much information as we can in a situation like this. |
Thanks for double checking this @alowdon. I have changed the title of the issue accordingly. I agree that this is not desired behavior; but we will have to maintain this behavior for the existing users as what might look like a bug to us might be an expected behavior to them and I don't want to introduce a bug for some users by fixing a bug for others. I have flagged this to be fixed as part of V2 which will include breaking changes. Until then you could wrap this with your own API and make it behave! |
@MehdiK If I were to fix this bug should I just do a pull request and comment it as for V2? Or is there a repo for V2? |
@cusmonaut a separate repo would diverge from this one very quickly and so does a PR that stays here for a while. The only way to have this now would be to add an optional parameter to the method that indicates what should happen to special and non-ascii characters defaulting to the current approach. Something like:
|
Hi, Titlize have some problems with non standart chars. For example there dotless and dotted i letter and this cause some problems. Consider a text which contains dotless small i letter in it, like "kadın sesi" (which means "woman voice" in english btw) |
On a second thought, due to this bug, I don't think anyone's using |
This bug is in StringHumanizeExtensions:FromPascalCase(string input) string |
I'm using I found a workaround by calling |
Thanks for the input @chris03. That's actually a perfect use case and proves my assumption completely wrong. Again I think we should fix the bug. We accept PRs too :) |
@jeremysimmons Any chance you could take a stab at fixing that RegEx? |
@onovotny I'll take a peek. Thank you for asking. Why aren't we just using TextInfo.ToTitleCase http://referencesource.microsoft.com/#mscorlib/system/globalization/textinfo.cs,706 for this? |
@onovotny this is a portable assembly. TextInfo.ToTitleCase isn't available in portable assemblies. |
@onovotny this is a working regex you can plug into PascalCaseWordPartsRegex in StringHumanizeExtensions. PascalCaseWordPartsRegex = new Regex(@"\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?=\p{Lu}\p{Ll}|[0-9]|\b)", Does not work with @@ -> @@, still produces @@ -> String.Empty. This should work for users that have a language that characters outside basic Latin. I would have done a pull request, but I'm having some issues getting the dev branch working locally. |
IMHO any unrecognized characters should be left as is. |
I'm with @mexx. |
This might be by design, because this is not necessarily appropriate input, but if you try the following, for example:
"Майк".Titleize()
"@@".Titleize()
then it will throw an InvalidOperationException:
I would expect it to either throw a more relevant exception, or just to return the original input?
(P.S. Humanizer is a great library - thanks for producing and maintaining it!)
The text was updated successfully, but these errors were encountered: