揮発性のメモ2

http://d.hatena.ne.jp/iww/

SourceTree Windows版で文字化けが起こる 問題の解決

Windows版のSourceTreeで、文字コードUTF-8のファイルで、なんでか特定のファイルだけ文字化けが起こる。


http://www.tokyo-web.jp/news/archives/sourcetree-windowsutf8bom.html
どうも、BOMをつけていれば問題ないらしい。
しかしPHPファイルでBOMなんてつけていたら即死してしまう。


[SRCTREEWIN-952] Diff doesn't detect UTF-8 without BOM - Create and track feature requests for Atlassian products.
本家の掲示板を見ていたら、この記事を発見。

The problem is that in order to detect the encoding when there's no BOM, SourceTree samples the first 512 bytes. If no extended characters are found in that it defaults to the operating system's default setting.

BOMが無いときは先頭512バイトをサンプリングして、それでわかんなかったらシステムデフォルトの文字コードにする。
つまり、先頭512バイトの中になんか適当な日本語を書いておけば解決すると!

<?
/* 今日はいい天気です */

文字化けしているすべてのソースの先頭にこのコードを挿入することで 文字化けは解消された。


しかし、いくつかのファイルでは解決されなかった。

<?
/* あああああいいいいいうううううええええ */

19文字くらいぶっこめばどんなファイルでも回避可能っぽい
これでも足りなければどんどん伸ばせばそのうちいける