0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

wget のファイル名エスケープ --restrict-file-names

Posted at

wget では --restrict-file-names を使用することで、ファイル名をエスケープして指定したファイルを保存することができます。

どのようにファイル名が変換されるのかをまとめたいと思います。

1. 指定できるモード

カンマ区切りで併用可 (一部モードは不可) 。

  • unix, windows
    • OS 用にファイル名を制限。複数 OS 併用は不可 (モードが上書きされる)
  • lowercase, uppercase
    • 全てのアルファベットを小文字・大文字に変換する
    • もともとアルファベトである文字も、% エンコードされて出力されるアルファベットも、どちらにも適用される
  • nocontrol
    • 制御文字をエスケープしなくなります
    • UTF-8 のファイル名が使用できる環境で、UTF-8 の制御コードをそのまま保つために使用するようです
  • ascii
    • ASCII 文字以外を全てエスケープします

2. OS モードごとのファイル名エスケープの規則

2.1. Unix

/ と制御文字が % エンコードされます。

  • / -> %2F
    • ディレクトリの区切り文字でなく、 ? の後ろに続くクエリパラメータにある / が % エンコードされる
    • 例:test?param/ -> test?param%2F
  • 制御文字 0–31, 128–159 -> %00-%1F, %80-%9F

2.2. Windows

  • Windows でファイル名に使用できない記号 \ / : * ? " < > |
    • 基本的にすべて % エンコード (例外有り。後述)
  • 制御文字 0–31, 128–159 -> %00-%1F, %80-%9F
  • クエリパラメータの区切り文字の ? -> @
    • 区切り文字の ? のみ @ に置換
    • クエリパラメータに含まれる ? は % エンコード
    • 例:test?param? -> test@param%3F
  • ホスト名とポート番号の区切り文字の : -> +
    • ホスト名のディレクトリを作成するオプションを使用しているとき、ホスト名とポート番号を指定している場合に適用される
    • ファイル名やクエリパラメータに含まれる : は % エンコード
    • 例:example.com:8000/test:?: -> example.com+8000/test%3A@%3A

参考「‘--restrict-file-names=modes’ - GNU Wget 1.20 Manual

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?