Closed Bug 1272781 Opened 4 years ago Closed 4 years ago

nsEscape should work with ns(C)Strings and not with char pointers

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla49
Tracking Status
firefox49 --- fixed

People

(Reporter: baku, Assigned: baku)

Details

(Whiteboard: btpp-active)

Attachments

(1 file)

There are many issues with the current implementations: 1. memory allocation, 2. dealing with '\0' strings.
Attached patch escape.patchSplinter Review
I don't know if we want to get rid of nsEscape completely. That seems a bigger task.
Assignee: nobody → amarchesini
Attachment #8753365 - Flags: review?(bugs)
Comment on attachment 8753365 [details] [diff] [review]
escape.patch

>@@ -82,18 +82,17 @@ NS_IMETHODIMP  nsTextToSubURI::ConvertAn
>       if (NS_SUCCEEDED(rv = encoder->Convert(text,&ulen, pBuf, &outlen))) {
>         // put termination characters (e.g. ESC(B of ISO-2022-JP) if necessary
>         int32_t finLen = bufLen - outlen;
>         if (finLen > 0) {
>           if (NS_SUCCEEDED(encoder->Finish((char *)(pBuf+outlen), &finLen))) {
>             outlen += finLen;
>           }
>         }
>-        pBuf[outlen] = '\0';
>-        *_retval = nsEscape(pBuf, url_XPAlphas);
>+        *_retval = nsEscape(pBuf, outlen, nullptr, url_XPAlphas);
so that outlen isn't the length. It is the last index. But I guess that doesn't matter here since it is always \0, and the actual
string data ends at length outlen.



>-        char *escapedDate = nsEscape(buffer, url_Path);
>-        aString.Append(escapedDate);
>-        free(escapedDate);
>+        nsAutoCString bufferStr;
>+        bufferStr.Append(buffer);
Nit, couldn't you use some DependentString here?
Attachment #8753365 - Flags: review?(bugs) → review+
Whiteboard: btpp-active
https://hg.mozilla.org/mozilla-central/rev/650e566ffa9e
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla49
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.