Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编码(encode)与转义(escape) #77

Open
teazean opened this issue Nov 21, 2017 · 2 comments
Open

编码(encode)与转义(escape) #77

teazean opened this issue Nov 21, 2017 · 2 comments

Comments

@teazean
Copy link
Owner

teazean commented Nov 21, 2017

综述:encode ~= escape

只能说大部分通常的使用都有约定的名称,比如

  • urlurl encode
  • htmlhtml escape
  • js stringescape sequence
@teazean teazean changed the title 关于编码 编码(encode)与转义(escape) Jan 2, 2018
@teazean
Copy link
Owner Author

teazean commented Jan 2, 2018

  1. html escape: 通常是以 &# 开头,如 �

  2. url encode: 都是以 % 开头,本身有几个适用于不同场景的协议,比如目前最新的 RFC3896,也有适用于 http/(post|get)x-www-form-urlencoded

    wiki-链接:https://en.wikipedia.org/wiki/Percent-encoding#The_application.2Fx-www-form-urlencoded_type
    实现:%E8%AE%B8这种是的三字节编码,可以转成\u8bb8这边unicode编码(utf-8采用可变长字节编码,以三字节编码为例,固定格式1110xxxx 10xxxxxx 10xxxxxx,可以转成三字节码,同时也可以对其中的变化部分xxx进行编码,四个一组成为\u8bb8这种16进制的编码);

         Unicode符号范围 | UTF-8编码方式
         (十六进制) | (二进制)
         —————————————————————–
         0000 0000-0000 007F | 0xxxxxxx
         0000 0080-0000 07FF | 110xxxxx 10xxxxxx
         0000 0800-0000 FFFF | 1110xxxx 10xxxxxx 10xxxxxx
         0001 0000-0010 FFFF | 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
         // 前面是unicode编码`\uFFFF`, 后面代表需要在网络上如何传输
    
  3. js escape sequence: 比如 \xhh\uhhhh\u{hhh*}\ooo,具体见issue-链接

  4. js integer literal: mdn-链接,固定以 0[oOxXbB] 2 个字符开始。

    16进制:0xhhh* 0Xhhh*
    8进制:0oooo* 0Oooo*
    2进制:0bbbb* 0Bbbb*

@teazean
Copy link
Owner Author

teazean commented Jan 2, 2018

关于git下中文输出八进制的转码\xxx,git默认配置core.quotepath为true,会对中文文件名、中文路径转义成\xxx\xxx这种编码。可以通过设置下面来更改。

    git config --global core.quotepath false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant