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]: string/truncate behaves abnormally when truncating strings to length 3 #2630

Closed
2 tasks done
Snehil-Shah opened this issue Jul 20, 2024 · 2 comments · Fixed by #2635
Closed
2 tasks done

[BUG]: string/truncate behaves abnormally when truncating strings to length 3 #2630

Snehil-Shah opened this issue Jul 20, 2024 · 2 comments · Fixed by #2635
Assignees
Labels
Bug Something isn't working.

Comments

@Snehil-Shah
Copy link
Member

Snehil-Shah commented Jul 20, 2024

Description

Encountered an error when truncating strings to length 3.

Demo

image

Reproduction

  • truncate any string to length 3.

Expected Results

In [1]: truncate('hell', 3)
Out[1]: '...'

In [2]: ans.length
Out[2]: 3

Actual Results

In [1]: truncate('hell', 3)
Out[1]: 'hell...'

In [2]: ans.length
Out[2]: 7

Version

https://github.com/stdlib-js/stdlib/tree/c89a171db9b4664582fab09dc95a5cc3b58f9f21

Environments

Node.js

Node.js / npm Version

Node @20.13.1, npm @10.5.2

Platform

Ubuntu 20.04.6 LTS (container)

Checklist

  • Read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
@Snehil-Shah Snehil-Shah added the Bug Something isn't working. label Jul 20, 2024
@Snehil-Shah Snehil-Shah changed the title [BUG]: string/truncate behaves abnormally when truncating strings of length 4 [BUG]: string/truncate behaves abnormally when truncating strings to length 3 Jul 20, 2024
@Snehil-Shah
Copy link
Member Author

image

And also, should the string be truncated if the target length is equal to the given string's length? I think not..

@kgryte
Copy link
Member

kgryte commented Jul 20, 2024

should the string be truncated if the target length is equal to the given string's length?

No. I don't think so.

truncate any string to length 3.

Yes, that seems like a bug.

@Snehil-Shah Snehil-Shah self-assigned this Jul 20, 2024
@kgryte kgryte closed this as completed in 4345839 Jul 20, 2024
gunjjoshi pushed a commit to gunjjoshi/stdlib that referenced this issue Aug 21, 2024
PR-URL: stdlib-js#2635
Closes: stdlib-js#2630
Reviewed-by: Athan Reines <kgryte@gmail.com>
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants