Closed Bug 315184 Opened 19 years ago Closed 19 years ago

String.replace, alert is broken in somecase

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
major

Tracking

()

RESOLVED INVALID

People

(Reporter: yasheng, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051025 Firefox/1.5
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051025 Firefox/1.5

I'm using a function html2ansi(str) to replace some strings in str. The parameter 'str' came from the content of a editable iframe. But when the content of this iframe is copied from Mozilla (either 1.0.7 or 1.5 rc1) it self, 

         str.replace(/\n/gi, '')

will replace some blanks to ''. If it was copied from a IE window, str.replace just decrease the lenght of str a little.

I modified the program to the following, but the problem is still there,

function html2ansi(str)
{
(1)   alert('length: '+ str.length + ' '+ str);
      str=str.replace(/\n/gi, '<tmpstring>');
      str=str.replace(/<tmpstring>/, '');
(2)   alert('length: '+ str.length + ' '+ str);
      ...
(3)   alert(str);
      return str;
}

The line (1) gives,

length: 144 The days of a program living as a single entity are all but gone. Today's programs need to be more versatile and expandable. The simpest way to 

The line (2) gives the following. VERY WIRED. At line (2) there is actually
no '<tmpsting>' in str, but '<tmpstring>' is displayed in 'alert'.

length: 153 The days of a program living as a single entity are all but gone. Today's programs need to be more versatile and expandable. The simpest<tmpstring>way to 

At line (3), alert still gives '....<tmpstring>...', but in the returned value,
there is actually no '<tmpstring>'.

I can not make a single html file to repeat this yet. But it happens every time
on my website (a Chinese website, GB2312, not English). If you want to look at it, send me a email (yasheng@gmail.com) for a step by step instruction.




Reproducible: Always
I write a example page on

       http://tttan.com/strreplace.html

which repeats this bug everytime.
Hint... the lost spaces were just at the line breaks of the alert window before
the replacement. Even if the 'alert()' is removed, you lose the same spaces.
Ok, I got it. Firefox generated some unwanted line breaks.

(In reply to comment #2)
> Hint... the lost spaces were just at the line breaks of the alert window before
> the replacement. Even if the 'alert()' is removed, you lose the same spaces.
> 

Status: UNCONFIRMED → RESOLVED
Closed: 19 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.