问题
Steps to repro the issue:
Add a file to my P4 server, the file is detected as 'utf8' file type.
The file I added is utf8 encoding without BOM.
nobomb show in vim
p4 client detect it as 'utf8'
If I do the same steps on other device, the file type is detected as 'unicode';
- Delete the file from local, and then sync it from server. issue occur: the file become utf8 with BOM.
sync the file, the file become utf with BOM
As you know, BOM in html file can cause lots of issue....Is there anyone who can help me to solve this issue?
Environment:
Client version: Rev. Perforce Visual Client/MACOSX107X86_64/2015.2/1312139
p4 server is in "unicode" mode.
- P4CHARSET of the workstation is set to utf8.
回答1:
Files of type 'utf8' always sync with the BOM - 'utf8' type is designed that way (see relnotes, #998379). If you don't want the BOM you're going to have to change it to 'text' or 'unicode'.
What you describe is a known bug(job083614) in your 15.2: "if P4CHARSET=utf8 and server is unicode and file has bytes >x80 and is valid utf8" then file is detected as utf8, should be unicode. This fix should hopefully (no promises) be in 16.2.
Earlier p4 clients <= 15.1 should detect it as 'unicode'.
If you don't want type 'utf8' but rather 'unicode':
- add your file with "p4 add -t unicode <file>"
- change the file's type before submitting.
- use typemap to make all files with certain extension add as 'unicode'.
- use a client (p4v, p4 command line) <= 2015.1 to add the files. Subsequent syncs/submits can be later versions.
You can also have a trigger to prevent utf8 file types from being submitted(change-submit)
回答2:
I believe the answers you are looking for can be found in the Perforce Internationalization Notes
In your question, you linked to the 2014.2 Internationalization Notes, but the utf8 filetype is newer than that; it was added in the 2015.2 release. So evidently your server is at release 2015.2 or higher. I linked to the 2016.1 Internalization notes. It is best to read the notes for the exact version of the server you are using.
The way that the files appear on your workstation is a combination of:
- The server's "unicode" setting: you appear to have a Unicode-enabled server
- The file's type (unicode, utf8, or utf16): you appear to have files of type unicode and utf8, at least
- The P4CHARSET of your workstation. As of release 2014.2, if you do not explicitly set P4CHARSET, the server will attempt to assign a value automatically.
Since it appears that you are using P4V to sync the files to your workstation, you also have to consider what settings P4V is applying on your behalf. You might find it more clear to start by using the 'p4' command-line tool to sync certain files to your workstation. You can then experiment with different file types, different P4CHARSET settings, etc., until you find the combination that gives you the results you expect.
But, again, be careful to note the exact versions of the client and server software that you are using, and to read the notes that apply exactly to those versions, as several of these behaviors have changed recently and that may be confusing you.
来源:https://stackoverflow.com/questions/38320814/bom-issue-in-unicode-perforce-server