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

Titleize doesn't capitalize first word in sub-string #28312

Closed
zinosama opened this issue Mar 6, 2017 · 4 comments
Closed

Titleize doesn't capitalize first word in sub-string #28312

zinosama opened this issue Mar 6, 2017 · 4 comments

Comments

@zinosama
Copy link
Contributor

zinosama commented Mar 6, 2017

Steps to reproduce

str = "i said 'the first word should be cap'."
=> "i said 'the first word should be cap'."
str.titleize
=> "I Said 'the First Word Should Be Cap'."

Expected behavior

"I Said 'The First Word Should Be Cap'."

Actual behavior

"I Said 'the First Word Should Be Cap'."

System configuration

Rails version: 5.0.1

Ruby version: 2.3.3

It seems like this is the commit that introduced this behavior - the lookbehind operator added in the PR doesn't match any character behind a single quotation mark, even when there's whitespace before that quotation mark.

I'm no expert in regex, but I can create a PR to revert to the previous behavior and add a test case for this.

@pixeltrix
Copy link
Contributor

@zinosama since this behaviour has been around since 2012 I don't want to simply revert - we should try to fix this.

@matthewd
Copy link
Member

matthewd commented Mar 6, 2017

Looks like /\b(?<!\b['’`])[a-z]/ might do it

@pixeltrix
Copy link
Contributor

pixeltrix commented Mar 6, 2017

@matthewd hmm, I went with /\b(?<!\w['’`])[a-z]/ - any issues you can see with that?

@matthewd
Copy link
Member

matthewd commented Mar 6, 2017

Nope; as this is already zero-width, they should be identical 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants