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

Fix corrupted utf-8 strings after trimming cell values #1517

Merged
merged 5 commits into from
Apr 12, 2023

Conversation

IAkumaI
Copy link
Contributor

@IAkumaI IAkumaI commented Apr 10, 2023

Usage value[:TotalCellChars] is incorrect. If value contains utf-8 string it may corrupt the last symbol in value.

PR Details

Bug fix of slicing strings in Go

Description

Excel has upper limit of character count which is 32767, but excelize checks value length by bytes instead by characters.
If I put utf-8 value (repeated 17000 times two-bytes symbol "Ы", for example) to a cell, excelize won't show any error, but file will be corrupted. Excel will show error on this file. Mac Numbers doesn't show any error, but empty cell and half-empty file.

Related Issue

[

](https://github.com//issues/1518)

Motivation and Context

How Has This Been Tested

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Usage value[:TotalCellChars] is incorrect. If value contains utf-8 string it may corrupt the last symbol in value.
@IAkumaI
Copy link
Contributor Author

IAkumaI commented Apr 10, 2023

Maybe it is better to use https://pkg.go.dev/unicode/utf8#RuneCountInString instead of converting whole string evert method call.

@xuri xuri added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 10, 2023
Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR. I've left some comments.

cell.go Outdated Show resolved Hide resolved
cell.go Outdated Show resolved Hide resolved
cell_test.go Outdated Show resolved Hide resolved
@IAkumaI
Copy link
Contributor Author

IAkumaI commented Apr 10, 2023

It's done, but "resolve conversation" button doesn't work. Don't know why :(
UPD: It's ok, just some github lags..

@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2023

Codecov Report

Merging #1517 (141e06a) into master (799317e) will not change coverage.
The diff coverage is 100.00%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@           Coverage Diff           @@
##           master    #1517   +/-   ##
=======================================
  Coverage   98.66%   98.66%           
=======================================
  Files          31       31           
  Lines       24337    24337           
=======================================
  Hits        24013    24013           
  Misses        214      214           
  Partials      110      110           
Flag Coverage Δ
unittests 98.66% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
cell.go 98.34% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@xuri xuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contribution.

@xuri xuri merged commit 635ec33 into qax-os:master Apr 12, 2023
fudali113 pushed a commit to fudali113/excelize that referenced this pull request Apr 17, 2023
xuri pushed a commit to JDavidVR/excelize that referenced this pull request Jul 11, 2023
jenbonzhang pushed a commit to jenbonzhang/excelize that referenced this pull request Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants