Closed Bug 238445 Opened 20 years ago Closed 20 years ago

Can't save page as file with chinese filename

Categories

(Core :: Internationalization, defect)

x86
OS/2
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: ccwu, Assigned: mkaply)

Details

Attachments

(1 file, 2 obsolete files)

User-Agent:       Mozilla/5.0 (OS/2; U; Warp 4.5; en-US; rv:1.7a) Gecko/20040225
Build Identifier: Mozilla/5.0 (OS/2; U; Warp 4.5; en-US; rv:1.7a) Gecko/20040225

Can't save page as file with chinese filename

Reproducible: Always
Steps to Reproduce:
1.Open one page
2.Click File->Save Page As
3.Add any Chinese character to filename
4.Click Save
5.The dialog was closed and nothing happened
Assignee: file-handling → smontagu
Component: File Handling → Internationalization
QA Contact: ian → amyy
I have no idea how this one has existed so long.

Problem is here:

http://lxr.mozilla.org/seamonkey/source/xpcom/io/nsNativeCharsetUtils.cpp#1019

resultLen must be more than inputLen, since inputLen is number of unicode chars
and we could have more native chars than we had unicode.

Working on a solution.
Assignee: smontagu → mkaply
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch Fix for problem (obsolete) — Splinter Review
Buffer for conversion needs to be twice as many chars as the unicode string
since one unicode char can become two platform bytes.
Attachment #144753 - Flags: review+
Comment on attachment 144753 [details] [diff] [review]
Fix for problem

> +    size_t inputLen = (flat.Length()*2) + 1; // include null char

Please make that
+    size_t inputLen = (flat.Length()*sizeof(PRUnichar)) + 1; // include null
char
I didn't mean sizeof(PRUnichar), I meant two.

The issue here is converting from Unicode to a native charset. the sizeof
PRUnichar is irrelvant.

When x number of unicode characters is converted to a native character set (not
UTF-8 or GB18030), the maximum number of chars that can result is x*2.

It has nothing to do with the size of a PRUnichar.
Fix checked in.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Michael Kaply wrote:
> When x number of unicode characters is converted to a native character set 
> (not UTF-8 or GB18030), the maximum number of chars that can result is x*2.
> It has nothing to do with the size of a PRUnichar.

Ouch... you're right... I didn't saw that from the patch, only from looking at
the original source...
The patch is not quite right.  The length of the resulting string is too long.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attached patch fix v2 (obsolete) — Splinter Review
The inputLen should not be set to length*2+1.  We were converting twice as much
data.
Attachment #144753 - Attachment is obsolete: true
Attached patch fix v2.1Splinter Review
Oops, removed too many comments.  Also, we don't need to worry about the
terminating null.
Attachment #144797 - Attachment is obsolete: true
Attachment #144801 - Flags: review?(mkaply)
(In reply to comment #4)

> When x number of unicode characters is converted to a native character set (not
> UTF-8 or GB18030), the maximum number of chars that can result is x*2.

  It's probably true on OS/2, but it's not always the case in general. In
addition to GB18030,  EUC-JP, EUC-KR and EUC-TW need more than two bytes for
some Unicode characters.


The new patch has been checked in to trunk and 1.4
Status: REOPENED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → FIXED
Attachment #144801 - Flags: review?(mkaply)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: