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

🐛 Incorrect Title Formatting for Hyphenated and Apostrophe Words #9

Closed
a-tokyo opened this issue Jan 31, 2025 · 0 comments · Fixed by a-tokyo/TitleCaser#1 · May be fixed by #10
Closed

🐛 Incorrect Title Formatting for Hyphenated and Apostrophe Words #9

a-tokyo opened this issue Jan 31, 2025 · 0 comments · Fixed by a-tokyo/TitleCaser#1 · May be fixed by #10

Comments

@a-tokyo
Copy link

a-tokyo commented Jan 31, 2025

Bug Report: Incorrect Title Formatting for Hyphenated and Apostrophe Words

Describe the bug

When formatting job titles that include hyphens or apostrophes (e.g., "t-mobile", "coca-cola", "e-commerce"), the TitleCaser returns incorrect results (e.g., "t[mobile", "coca[cola", "e[commerce") due to an incorrect joiner being used when reassembling the split word parts.

To Reproduce

Steps to reproduce the behavior:

  1. Use the TitleCaser on strings such as "t-mobile", "coca-cola", or "e-commerce".
  2. Execute the tests (e.g., run npm test or a similar command).
  3. Observe that the output is incorrect: instead of "T-Mobile", "Coca-Cola", or "E-Commerce", the returned strings contain a "[" character (e.g., "t[mobile").

Expected behavior

The TitleCaser should correctly reassemble the split word parts using the proper delimiter. For instance:

  • "t-mobile" should be transformed into "T-Mobile".
  • "coca-cola" should be transformed into "Coca-Cola".
  • "e-commerce" should be transformed into "E-Commerce".

Screenshots

If applicable, add screenshots to help explain your problem.
(No screenshots provided)

Desktop (please complete the following information):

  • OS: macOS / Windows / Linux
  • Browser: N/A (issue appears in a Node.js environment)
  • Version: v1.7.0

Smartphone (please complete the following information):

  • Device: N/A
  • OS: N/A
  • Browser: N/A
  • Version: N/A

Additional context

The bug is caused by the correctTerm function in the TitleCaserUtils class. It uses delimiters.source.charAt(0) to join the parts after splitting the word. When using the default delimiter regex /[-']/, delimiters.source.charAt(0) returns "[" instead of the expected hyphen or apostrophe. The solution was to determine the correct joiner based on whether the original word includes a hyphen or an apostrophe.

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