The character whose code is less than 32 are unchanged in Random Batch Tester except 0, 9, 10, 13 ============================================ 0===>Lost 1 2 3 4 5 6 7 8 9===>32 10===>32 11 12 13===>32 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32----(Space)--- ============================================ ============================================ Bug 1 (PHP側) -------------------------------------------- [Wrong!]
-------------------------------------------- [Correct!]
-------------------------------------------- htmlspecialchars が & を & に変換していしまっていた。 htmlspecialcharsは必要なかった。 ============================================ ============================================ Bug 2 (JS側) -------------------------------------------- [Wrong!] const txt=document.getElementById("log").innerText; const txt=document.getElementById("log").innerHTML; -------------------------------------------- [Correct!] const txt=document.getElementById("log").textContent -------------------------------------------- innerTextとinnerHTMLを勘違いしていた。 innerTextは純粋なText表現によるHTMLを返すのではなく、
のようなHTMLタグを抜く。 innerHTMLは純粋なText表現によるHTMLを返すのではなく、 < から <のようなエスケープが行われる。 従って、純粋なTextが欲しい場合は、textContentを使用する。 注:textContentでも以下の点には注意が必要である。 (1) "\x00"の文字は、消される。 (2) "\r"の文字は、textContentで取り出した場合、"\n" に変換される。 ============================================