Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

[ASTextNode] Fix out-of-bounds error when truncation string is longer than the original string. - #1111

Merged
appleguy merged 1 commit into
facebookarchive:masterfrom
yury:fix-_linkAttributeValueAtPoint-crash
Jan 26, 2016
Merged

[ASTextNode] Fix out-of-bounds error when truncation string is longer than the original string.#1111
appleguy merged 1 commit into
facebookarchive:masterfrom
yury:fix-_linkAttributeValueAtPoint-crash

Conversation

@yury

@yury yury commented Jan 25, 2016

Copy link
Copy Markdown
Contributor

Actually it is possible that truncated string is longer then original
string.

For example, original string:

hello
this is
very long
message here
and there

with maximumNumberOfLines=4, truncationAttributedString = ' ...' and
additionalTruncationMessage = 'read more'

will give

hello
this is
very long
message here ... read more

So [attributedString attribute:attributeName atIndex:characterIndex longestEffectiveRange:&range inRange:visibleRange] will crash.

Actually it is possible that truncated string is longer then original
string.

For example, original string:

```
hello
this is
very long
message here
and there
```

with maximumNumberOfLines=4, truncationAttributedString = ' ...' and
additionalTruncationMessage = 'read more'

will give

```
hello
this is
very long
message here ... read more
```

So `[attributedString attribute:attributeName atIndex:characterIndex
longestEffectiveRange:&range inRange:visibleRange]` will crash.
@yury

yury commented Jan 25, 2016

Copy link
Copy Markdown
Contributor Author

Also related to #1110

@yury

yury commented Jan 25, 2016

Copy link
Copy Markdown
Contributor Author

Also, there are two unported commits from ComponentKit 1 and 2. I can port them with new PR

@appleguy

Copy link
Copy Markdown
Contributor

@yury thanks a lot for porting the other CK commits!! @ocrickard anything else we should be aware of? I wonder if there's a way to set up something similar to a Herald rule to notify me when text components change :)

@appleguy appleguy changed the title Fix Out of bounds error [ASTextNode] Fix out-of-bounds error when truncation string is longer than the original string. Jan 25, 2016
@appleguy appleguy added this to the 1.9.7 milestone Jan 25, 2016
appleguy added a commit that referenced this pull request Jan 26, 2016
[ASTextNode] Fix out-of-bounds error when truncation string is longer than the original string.
@appleguy
appleguy merged commit d70a955 into facebookarchive:master Jan 26, 2016
@appleguy

Copy link
Copy Markdown
Contributor

@yury could you send me an example test case for this so I can integrate it into the unit tests? If you're able to add a snapshot / unit test for this directly, that would be phenomenal too :). asyncdisplaykit@gmail.com

@yury

yury commented Jan 26, 2016

Copy link
Copy Markdown
Contributor Author

@appleguy ported to commits from component kit #1119.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants