-
Notifications
You must be signed in to change notification settings - Fork 7
Refactor string.substring usages to account for surrogate pair characters #7206
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ | |
| import org.labkey.api.util.NetworkDrive; | ||
| import org.labkey.api.util.PageFlowUtil; | ||
| import org.labkey.api.util.Path; | ||
| import org.labkey.api.util.StringUtilsLabKey; | ||
| import org.labkey.api.util.logging.LogHelper; | ||
| import org.labkey.api.view.ActionURL; | ||
| import org.labkey.api.view.FolderTab; | ||
|
|
@@ -1594,7 +1595,7 @@ public String getContainerNoun(boolean titleCase) | |
| String noun = _containerType.getContainerNoun(this); | ||
| if (titleCase) | ||
| { | ||
| return noun.substring(0, 1).toUpperCase() + noun.substring(1); | ||
| return StringUtilsLabKey.leftSurrogatePairFriendly(noun, 1).toUpperCase() + StringUtilsLabKey.rightSurrogatePairFriendly(noun, noun.length() - 1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, how should someone know if they should use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like discussed, I think generally a static constant endIndex is a good candidate for using those new methods. When paired with indexOf... as end, then probably substring is better. But each case needs to be evaluated separately to prioritize overflow/accuracy, etc. |
||
| } | ||
|
|
||
| return noun; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ | |
| import org.labkey.api.util.DebugInfoDumper; | ||
| import org.labkey.api.util.ExceptionUtil; | ||
| import org.labkey.api.util.MemTracker; | ||
| import org.labkey.api.util.StringUtilsLabKey; | ||
| import org.labkey.api.view.ViewServlet; | ||
|
|
||
| import java.io.InputStream; | ||
|
|
@@ -2876,7 +2877,7 @@ else if (o instanceof String) | |
| else | ||
| value = String.valueOf(o); | ||
| if (value.length() > 100) | ||
| value = value.substring(0, 100) + ". . ."; | ||
| value = StringUtilsLabKey.leftSurrogatePairFriendly(value, 100) + ". . ."; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This isn't a part of these changes but the names of these utility functions does not describe what they do. Consider a rename refactor to something like |
||
| logEntry.append("\n --[").append(i).append("] "); | ||
| logEntry.append(value); | ||
| Class<?> c = null==o ? null : o.getClass(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is this line in PageFlowUtil. Does it need to use these methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this one needs it. ext and mimeType both are unlikely to have special characters, so the endInd should be safe.