Closed
Bug 36656
Opened 25 years ago
Closed 24 years ago
ReplaceSubstring is acting funky
Categories
(Core :: XPCOM, defect, P3)
Tracking
()
VERIFIED
FIXED
M17
People
(Reporter: slogan, Assigned: slogan)
Details
(Whiteboard: [nsbeta2+] [7/25/2000])
Attachments
(1 file)
(deleted),
application/octet-stream
|
Details |
In IM away messages, users can use macros like %n to denote the name. I am
passing an away message that is equal to:
Hi %n, I'm out to lunch today is %d time is %t
The %d and %t seem to always work, but with %n, I get, first time I called it,
no replacement was made, and the second time, it replaced the %n twice with the
replacement string "SLOGAN621" in this case.
Here are some traces in gdb.
Breakpoint 2, nsCIMWnd::ProcessAwayMessage (this=0x8cd50a8, msg=0xbfffdcc4,
screenName=0x8f05fc0) at /opt/raptor/ns/AIMGlue/src/nsCAimIM.cpp:1137
1137 nsCAutoString msgStr( msg->GetUnicode() );
(gdb) n
1139 nsCOMPtr<nsIDateTimeFormat> gFormat;
(gdb) print msgStr
$1 = {<nsCString> = {<nsStr> = {mLength = 46, mCapacity = 63,
mCharSize = eOneByte, mOwnsBuffer = 0, {
mStr = 0xbfffdae4 "Hi %n, I'm out to lunch today is %d time is %t",
mUStr = 0xbfffdae4}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is %d time is
%t\000@ëG\035@\\\000\000\000\200½\215A\220zU\b"}
(gdb) n
1140 nsString aResultTime("");
(gdb) n
1141 nsString aResultDate("");
(gdb) n
1149 ) {
(gdb) n
1150 msgStr.ReplaceSubstring( "%t", aResultTime.GetUnicode()
);
(gdb) n
1151 msgStr.ReplaceSubstring( "%d", aResultDate.GetUnicode()
);
(gdb) n
1154 msgStr.ReplaceSubstring( "%n", screenName );
(gdb) print msgStr
$2 = {<nsCString> = {<nsStr> = {mLength = 61, mCapacity = 63,
mCharSize = eOneByte, mOwnsBuffer = 0, {
mStr = 0xbfffdae4 "Hi %n, I'm out to lunch today is 04/20/00 time is
11:30:02 PM", mUStr = 0xbfffdae4}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is 04/20/00 time is 11:30:02
PM\000U\b"}
(gdb) n
00:08:02 Socket 08CA6660: readable
1156 msg->Assign( msgStr );
(gdb) print msgStr
$3 = {<nsCString> = {<nsStr> = {mLength = 61, mCapacity = 63,
mCharSize = eOneByte, mOwnsBuffer = 0, {
mStr = 0xbfffdae4 "Hi %n, I'm out to lunch today is 04/20/00 time is
11:30:02 PM", mUStr = 0xbfffdae4}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is 04/20/00 time is 11:30:02
PM\000U\b"}
(gdb) n
1157 return NS_OK;
and the case where it replaced twice:
Breakpoint 2, nsCIMWnd::ProcessAwayMessage (this=0x8cd50a8, msg=0xbfffdc3c,
screenName=0x8ed90d8) at /opt/raptor/ns/AIMGlue/src/nsCAimIM.cpp:1137
1137 nsCAutoString msgStr( msg->GetUnicode() );
(gdb) n
1139 nsCOMPtr<nsIDateTimeFormat> gFormat;
(gdb) n
1140 nsString aResultTime("");
(gdb) n
1141 nsString aResultDate("");
(gdb) print msgStr
$7 = {<nsCString> = {<nsStr> = {mLength = 46, mCapacity = 63,
mCharSize = eOneByte, mOwnsBuffer = 0, {
mStr = 0xbfffdb08 "Hi %n, I'm out to lunch today is %d time is %t",
mUStr = 0xbfffdb08}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is %d time is
%t\000¿øQÍ\b.\000\000\000àª\222A\003\000\000"}
(gdb) n
1149 ) {
(gdb) n
1150 msgStr.ReplaceSubstring( "%t", aResultTime.GetUnicode()
);
(gdb) n
1151 msgStr.ReplaceSubstring( "%d", aResultDate.GetUnicode()
);
(gdb) n
1154 msgStr.ReplaceSubstring( "%n", screenName );
(gdb) print msgStr
$8 = {<nsCString> = {<nsStr> = {mLength = 61, mCapacity = 63,
mCharSize = eOneByte, mOwnsBuffer = 0, {
mStr = 0xbfffdb08 "Hi %n, I'm out to lunch today is 04/20/00 time is
11:32:15 PM", mUStr = 0xbfffdb08}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is 04/20/00 time is 11:32:15
PM\000\000"}
(gdb) n
1156 msg->Assign( msgStr );
(gdb) print msgStr
$9 = {<nsCString> = {<nsStr> = {mLength = 75, mCapacity = 128,
mCharSize = eOneByte, mOwnsBuffer = 1, {
mStr = 0x8eca650 "Hi SLOGAN621SLOGAN621, I'm out to lunch today is
04/20/00 time is 11:32:15 ", mUStr = 0x8eca650}}, _vptr. = 0x401e6960},
mBuffer = "Hi %n, I'm out to lunch today is 04/20/00 time is 11:32:15
PM\000\000"}
Looks like the problem happened when we grew the buffer (and capacity) from 63
to 128 and the bits we copied back.
Updated•25 years ago
|
Status: NEW → ASSIGNED
Target Milestone: --- → M17
Comment 2•25 years ago
|
||
Core functionality needs to work... or else we will sufer all over the place.
PDT+
Whiteboard: [nsbeta2+]
Comment 3•25 years ago
|
||
Syd, I think you may be calling this function incorrectly. Both arguments need
to already be the same character encoding, and the same encoding as the referent.
Additionally, both arguments need to be pointers. Not forcing this explicitly
may make you call into the version that takes to |ns[C]Strings| as parameters,
which rickg explictly notes in the code
//WARNING: This is not working yet!!!!!
but no further details of what is wrong or what he intended to happen. Where is
the source that exhibits these symptoms?
Comment 4•25 years ago
|
||
Yeah, that's the problem. You're just using a routine that is known not to work.
Theorectically, the pointer version works. I'd switch to that for now, until I
have a reasonable answer for you. Supposedly, rickg is replacing this entire
class soon, so I hesitate to fix a routine that will go away, and only one person
is calling. Till then, I'm assigning the bug back to you as asked me to.
Assignee: scc → syd
Status: ASSIGNED → NEW
Comment 5•25 years ago
|
||
Comment 6•25 years ago
|
||
Actually I'm not quite positive if the patch addresses the problem described in
this report. It fixes a bug occuring when replacing e.g. "&" with "&", where
the replacement pattern contains the search pattern. This lead to a (more or
less) infinite loop...
Comment 7•25 years ago
|
||
I guess I need to learn about bugzilla... The attachment is a .tar.gz archive.
Status: NEW → ASSIGNED
Whiteboard: [nsbeta2+] → [nsbeta2+] [7/25/2000]
Fixed - we've recoded the caller as per scc's suggestion, and this is no longer
an issue.
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
I tested the original error case and it worked fine for me. marking verified as
per Jan's request.
Status: RESOLVED → VERIFIED
You need to log in
before you can comment on or make changes to this bug.
Description
•