Open
Bug 1397045
Opened 7 years ago
Updated 2 years ago
Find, RFind, and Compare all have default parameter footguns
Categories
(Core :: XPCOM, enhancement)
Core
XPCOM
Tracking
()
NEW
Tracking | Status | |
---|---|---|
firefox57 | --- | affected |
People
(Reporter: erahm, Unassigned)
References
(Blocks 1 open bug)
Details
We have a few functions that are either only defined on char16_t versions of string classes or only on char versions. So for example sometimes 'Find' takes a string and offset that defaults to -1, but other times 'Find' takes a string and then a bool param indicating whether to use a case insensitive comparison or not and *then* an offset. So something like:
> int32_t Find(const nsTString<char>& aString, bool aIgnoreCase = false,
> int32_t aCount = -1) const;
>
> template <typename EnableIfChar16 = IsChar16>
> int32_t Find(const self_type& aString, int32_t aOffset = 0,
> int32_t aCount = -1) const;
I've found a few bugs where users were expecting just the `Find(str, offset)` version and were calling it with something like:
> // expects to use the offset version, but hits the `aIgnoreCase` version.
> nsCString aCStr;
> aCStr.Find(str, itr - start);
I think we'd be better off removing the `aIgnoreCase` version and adding something like `FindIgnoreCase` that only works with char params.
Assignee | ||
Updated•4 years ago
|
Component: String → XPCOM
Updated•2 years ago
|
Severity: normal → S3
You need to log in
before you can comment on or make changes to this bug.
Description
•