锁阳有什么功效| 圆是什么生肖| 螺旋杆菌阳性是什么病| 眼皮痒是什么原因| 4.22是什么日子| 欢喜冤家是什么意思| 25羟基维生素d是什么| 便秘吃什么中成药| 什么是玻尿酸| 马英九是什么生肖| cba什么意思| 有福是什么意思| 一什么木屋| 大便硬是什么原因| 射手座最配什么星座| 比基尼是什么意思| 为什么会得血管瘤| 看日出是什么生肖| ii是什么意思| 带状疱疹长什么样| 深圳车牌摇号需要什么条件| 秋葵什么人不能吃| 甲状腺结节忌口什么| 钓鲤鱼用什么饵料| 梦见好多动物是什么意思| 十一月什么星座| 眼睛肿痛什么原因| 什么是扁平疣图片| 头脑灵活是什么生肖| 股癣用什么药膏好得快| 什么是丛林法则| 印是什么意思| 闪婚是什么意思| 炖什么汤对肺部最好| 吃饭肚子疼是什么原因| 睡醒口干口苦是什么原因| 煲鸡汤放什么材料好| 皮肤炎症用什么药| 身体透支是什么意思| 潜意识是什么意思| 甘甜是什么意思| 女性尿血挂什么科| 用什么梳子梳头发最好| 马上风为什么拔不出来| 杜牧字什么号什么| 出淤泥而不染是什么花| 小暑是什么意思| abi医学上是什么意思| 舌炎是什么原因引起的怎样治疗| 疱疹是一种什么病| 百步穿杨是什么意思| 持续发烧不退是什么原因| 什么情况属于骗婚| 脚崴了吃什么药| gold什么意思| 七月份生日是什么星座| 吃茄子有什么坏处| 无缝衔接什么意思| 虫草适合什么人吃| 曙光什么意思| 早早孕有什么征兆| 什么的雷锋| 复方丹参片治什么病| 气垫是什么| 断片是什么意思| 什么颜色加什么颜色等于蓝色| 纺织厂是做什么的| 梦见面包是什么意思| 火把节是什么节日| 敢爱敢恨是什么意思| 丹凤眼是什么样| 过敏了吃什么药好| 双休什么意思| 血液科是看什么病| 血压低头疼是什么原因| 鸽子和什么一起炖汤最有营养| ganni是什么牌子| 中性粒细胞绝对值偏高是什么原因| 翠绿色配什么颜色好看| 狗感冒吃什么药| 头疼是什么病的前兆| 五味子有什么功效| 肠粉为什么叫肠粉| 梦见下牙掉了是什么征兆| 奀是什么意思| 念珠菌感染用什么药效果好| 人棉是什么面料| 夜盲症缺什么维生素| 口腔发苦是什么原因| 左腿疼是什么原因| 高原反应有什么症状| 胆囊结石需要注意什么| 两重天什么意思| 胡桃木色是什么颜色| 特仑苏是什么意思| 假性近视是什么意思| 头总出汗是什么原因| 易建联为什么不打nba| 黄瓜不能和什么食物一起吃| 怠工是什么意思| 六月底是什么星座| 白带清洁度lv是什么意思| 米粉是什么做的| 女人矜持是什么意思| 毒血症是什么病| 左眼皮一直跳是什么预兆| 3.3是什么星座| 敏感肌是什么意思| 辛辣是什么意思| 蜻蜓点水是什么行为| 避孕套是什么| 心阴不足吃什么中成药| 脑梗能吃什么水果| 睾丸炎有什么症状| 今夕何夕是什么意思| 唐筛检查什么| 生猴子是什么意思| 什么情况做肠镜| 不检点是什么意思| 肾亏吃什么药最好| 伤元气是什么意思| 海底捞是什么| 洗手做羹汤是什么意思| 梦见虱子是什么意思| 肠道为什么会长息肉| 什么空调最好| 核苷酸是什么| 鹿晗有什么歌| 钱学森发明了什么| 冷战是什么意思| 腹泻可以吃什么食物| 什么是遴选| e代表什么方向| 急性中耳炎吃什么药| 砷是什么东西| 戊土是什么土| 10月6日什么星座| 1944年属什么生肖| 全身发黄是什么原因| 做梦抓到很多鱼是什么征兆| 缠头是什么意思| 什么是三农| 白细胞低吃什么补| 血涂片检查什么病| 下雨了是什么意思| av是什么| 回归是什么意思| 子宫肌瘤伴钙化是什么意思| 血儿茶酚胺是查什么的| 静脉曲张是什么原因引起的| 腹泻是什么意思| 七个小矮人分别叫什么| 有什么水能代替美瞳水| 什么叫五官| 被蚊子咬了涂什么药膏| 双肾结晶什么意思| mico是什么意思| 头汗特别多是什么原因| prog是什么意思| 什么是处男| 眼睛出血是什么原因| 888红包代表什么意思| 上热下寒吃什么中成药| 骆驼吃什么| 大便不调是什么意思| 一岁宝宝能吃什么水果| 二氧化硅是什么东西| amass是什么牌子| 薄姬为什么讨厌窦漪房| iod什么意思| 雪燕是什么| 手脚心热是什么原因| 血脂高吃什么水果最好| 大忌什么意思| 生菜是什么菜| 小便尿道刺痛吃什么药| 大便是红色的是什么原因| 脖子粗大是什么原因| 复方氨酚烷胺胶囊是什么药| 无痛人流后需要注意什么| 家里为什么有蜈蚣| 鸟屎掉手上有什么预兆| 宫内膜回声不均匀是什么意思| 黑色五行属什么| 什么颜色加什么颜色等于白色| 脖子肿是什么原因| 尿多是什么问题| 情绪不稳定易怒烦躁是什么症状| 郑州有什么好玩的| 血糖偏高吃什么水果好| 宝宝经常发烧是什么原因| 肚脐中间疼是什么原因| 尾货是什么意思| 百花齐放是什么生肖| 早上出虚汗是什么原因| 广义货币m2是什么意思| 阳春三月指什么生肖| 王昆念什么| 沙悟净的武器叫什么| 肝属什么| 毕业答辩是什么| 黑绿色大便是什么原因| 龙生九子是什么生肖| dan是什么意思| 梦到被猪咬是什么意思| 牛头人是什么意思| 有胃病的人吃什么最养胃| 大便感觉拉不干净什么原因| 社招是什么意思| min是什么意思| 屁是什么气体| dw手表属于什么档次| 病毒感染有什么症状| 女性尿血是什么原因引起的| 伊始是什么意思| 无犯罪记录证明需要什么材料| 为什么梦不到死去的亲人| 琛读什么| 思密达什么意思| 女人梦见棺材是什么征兆| 龟头瘙痒用什么药膏| 什么是转氨酶| 鹿鞭泡酒有什么功效| 偷梁换柱是什么意思| 牛建读什么| 双环征是什么意思| 302是什么意思| 皮肤出现红点是什么原因| 血糖高可以吃什么主食| 大肠炒什么菜好吃| 九月初三是什么星座| hpmc是什么| 感冒咳嗽吃什么药止咳效果好| 慢性子宫颈炎是什么意思| hiv1是什么意思| 腰闪了挂什么科| 喉咙长期有痰是什么原因| 高硼硅玻璃是什么材质| 刘备的马叫什么| 自字五行属什么| 美尼尔综合征是什么原因引起的| 绿豆长什么样| aigle是什么牌子| 唇炎属于什么科| 梦见孩子哭是什么意思| 黑色碳素笔是什么笔| 跟单员是做什么的| 八股文是什么| 苹果像什么| 什么的孙悟空| 除异味用什么效果最好| 吃什么头发长的快| 开字五行属什么| 女生的小鸡鸡长什么样| 自带bgm是什么意思| 总胆红素偏高有什么危害| 浑水摸鱼是什么意思| 贝的偏旁有什么字| 为什么月经老是提前| 月经没来吃什么药可以催月经来| 晚上七点多是什么时辰| 男人长期喝什么茶最好| 碳水化合物是什么东西| 脑瘫是什么症状| 百度
blob: 50800614eb4f1d6df795ea1288f89e06ebdd6811 [file] [log] [blame]
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/350788890): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif
// Functions for canonicalizing "file:" URLs.
#include <string_view>
#include "base/strings/string_util.h"
#include "url/url_canon.h"
#include "url/url_canon_internal.h"
#include "url/url_file.h"
#include "url/url_parse_internal.h"
namespace url {
namespace {
bool IsLocalhost(const char* spec, int begin, int end) {
if (begin > end)
return false;
return std::string_view(&spec[begin], end - begin) == "localhost";
}
bool IsLocalhost(const char16_t* spec, int begin, int end) {
if (begin > end)
return false;
return std::u16string_view(&spec[begin], end - begin) == u"localhost";
}
template <typename CHAR>
int DoFindWindowsDriveLetter(const CHAR* spec, int begin, int end) {
if (begin > end)
return -1;
// First guess the beginning of the drive letter.
// If there is something that looks like a drive letter in the spec between
// begin and end, store its position in drive_letter_pos.
int drive_letter_pos =
DoesContainWindowsDriveSpecUntil(spec, begin, end, end);
if (drive_letter_pos < begin)
return -1;
// Check if the path up to the drive letter candidate can be canonicalized as
// "/".
Component sub_path = MakeRange(begin, drive_letter_pos);
RawCanonOutput<1024> output;
Component output_path;
bool success = CanonicalizePath(sub_path.maybe_as_string_view_on(spec),
&output, &output_path);
if (!success || output_path.len != 1 || output.at(output_path.begin) != '/') {
return -1;
}
return drive_letter_pos;
}
#ifdef WIN32
// Given a pointer into the spec, this copies and canonicalizes the drive
// letter and colon to the output, if one is found. If there is not a drive
// spec, it won't do anything. The index of the next character in the input
// spec is returned (after the colon when a drive spec is found, the begin
// offset if one is not).
template <typename CHAR>
int FileDoDriveSpec(const CHAR* spec, int begin, int end, CanonOutput* output) {
int drive_letter_pos = FindWindowsDriveLetter(spec, begin, end);
if (drive_letter_pos < begin)
return begin;
// By now, a valid drive letter is confirmed at position drive_letter_pos,
// followed by a valid drive letter separator (a colon or a pipe).
output->push_back('/');
// Normalize Windows drive letters to uppercase.
if (base::IsAsciiLower(spec[drive_letter_pos]))
output->push_back(static_cast<char>(spec[drive_letter_pos] - 'a' + 'A'));
else
output->push_back(static_cast<char>(spec[drive_letter_pos]));
// Normalize the character following it to a colon rather than pipe.
output->push_back(':');
return drive_letter_pos + 2;
}
#endif // WIN32
template<typename CHAR, typename UCHAR>
bool DoFileCanonicalizePath(const CHAR* spec,
const Component& path,
CanonOutput* output,
Component* out_path) {
// Copies and normalizes the "c:" at the beginning, if present.
out_path->begin = output->length();
int after_drive;
#ifdef WIN32
after_drive = FileDoDriveSpec(spec, path.begin, path.end(), output);
#else
after_drive = path.begin;
#endif
// Copies the rest of the path, starting from the slash following the
// drive colon (if any, Windows only), or the first slash of the path.
bool success = true;
if (after_drive < path.end()) {
// Use the regular path canonicalizer to canonicalize the rest of the path
// after the drive.
//
// Give it a fake output component to write into, since we will be
// calculating the out_path ourselves (consisting of both the drive and the
// path we canonicalize here).
Component sub_path = MakeRange(after_drive, path.end());
Component fake_output_path;
success = CanonicalizePath(sub_path.maybe_as_string_view_on(spec), output,
&fake_output_path);
} else if (after_drive == path.begin) {
// No input path and no drive spec, canonicalize to a slash.
output->push_back('/');
}
out_path->len = output->length() - out_path->begin;
return success;
}
template<typename CHAR, typename UCHAR>
bool DoCanonicalizeFileURL(const URLComponentSource<CHAR>& source,
const Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* new_parsed) {
DCHECK(!parsed.has_opaque_path);
// Things we don't set in file: URLs.
new_parsed->username = Component();
new_parsed->password = Component();
new_parsed->port = Component();
// Scheme (known, so we don't bother running it through the more
// complicated scheme canonicalizer).
new_parsed->scheme.begin = output->length();
output->Append("file://");
new_parsed->scheme.len = 4;
// If the host is localhost, and the path starts with a Windows drive letter,
// remove the host component. This does the following transformation:
// file://localhost/C:/hello.txt -> file:///C:/hello.txt
//
// Note: we do this on every platform per URL Standard, not just Windows.
//
// TODO(crbug.com/41299821): According to the latest URL spec, this
// transformation should be done regardless of the path.
Component host_range = parsed.host;
if (IsLocalhost(source.host, host_range.begin, host_range.end()) &&
FindWindowsDriveLetter(source.path, parsed.path.begin,
parsed.path.end()) >= parsed.path.begin) {
host_range.reset();
}
// Append the host. For many file URLs, this will be empty. For UNC, this
// will be present.
// TODO(brettw) This doesn't do any checking for host name validity. We
// should probably handle validity checking of UNC hosts differently than
// for regular IP hosts.
bool success =
CanonicalizeFileHost(source.host, host_range, *output, new_parsed->host);
success &= DoFileCanonicalizePath<CHAR, UCHAR>(source.path, parsed.path,
output, &new_parsed->path);
CanonicalizeQuery(parsed.query.maybe_as_string_view_on(source.query),
query_converter, output, &new_parsed->query);
CanonicalizeRef(parsed.ref.maybe_as_string_view_on(source.ref), output,
&new_parsed->ref);
return success;
}
} // namespace
int FindWindowsDriveLetter(const char* spec, int begin, int end) {
return DoFindWindowsDriveLetter(spec, begin, end);
}
int FindWindowsDriveLetter(const char16_t* spec, int begin, int end) {
return DoFindWindowsDriveLetter(spec, begin, end);
}
bool CanonicalizeFileURL(const char* spec,
int spec_len,
const Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* new_parsed) {
return DoCanonicalizeFileURL<char, unsigned char>(
URLComponentSource<char>(spec), parsed, query_converter,
output, new_parsed);
}
bool CanonicalizeFileURL(const char16_t* spec,
int spec_len,
const Parsed& parsed,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* new_parsed) {
return DoCanonicalizeFileURL<char16_t, char16_t>(
URLComponentSource<char16_t>(spec), parsed, query_converter, output,
new_parsed);
}
bool FileCanonicalizePath(const char* spec,
const Component& path,
CanonOutput* output,
Component* out_path) {
return DoFileCanonicalizePath<char, unsigned char>(spec, path,
output, out_path);
}
bool FileCanonicalizePath(const char16_t* spec,
const Component& path,
CanonOutput* output,
Component* out_path) {
return DoFileCanonicalizePath<char16_t, char16_t>(spec, path, output,
out_path);
}
bool ReplaceFileURL(const char* base,
const Parsed& base_parsed,
const Replacements<char>& replacements,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* new_parsed) {
URLComponentSource<char> source(base);
Parsed parsed(base_parsed);
SetupOverrideComponents(base, replacements, &source, &parsed);
return DoCanonicalizeFileURL<char, unsigned char>(
source, parsed, query_converter, output, new_parsed);
}
bool ReplaceFileURL(const char* base,
const Parsed& base_parsed,
const Replacements<char16_t>& replacements,
CharsetConverter* query_converter,
CanonOutput* output,
Parsed* new_parsed) {
RawCanonOutput<1024> utf8;
URLComponentSource<char> source(base);
Parsed parsed(base_parsed);
SetupUTF16OverrideComponents(base, replacements, &utf8, &source, &parsed);
return DoCanonicalizeFileURL<char, unsigned char>(
source, parsed, query_converter, output, new_parsed);
}
} // namespace url
梦见生孩子是什么意思解梦 失恋什么意思 ad和d3有什么区别 出虚恭是什么意思 hscrp高是什么感染
语言障碍挂什么科 cet是什么意思 九月五日是什么节日 les是什么意思 儿童身份证需要什么材料
警察是什么生肖 头疼是什么原因导致的 老是瞌睡是什么原因 催乳素是什么意思 晚饭吃什么英语怎么说
尿酸高是什么情况 申字五行属什么 你问我爱你有多深是什么歌 谈婚论嫁什么意思 血脂高是什么意思
月经期间不能吃什么hcv9jop0ns6r.cn izzue是什么牌子hcv7jop9ns8r.cn 布克兄弟什么档次chuanglingweilai.com 看灰指甲挂什么科hcv9jop7ns2r.cn 网络维护是做什么的hcv8jop5ns5r.cn
5月23是什么星座hcv8jop9ns4r.cn 那英姓什么qingzhougame.com 退位让贤是什么意思hcv9jop2ns0r.cn 两个土念什么字cj623037.com 用什么水和面烙饼最软hcv8jop5ns8r.cn
313什么意思hcv7jop6ns7r.cn 吃什么可以来月经最快最有效hcv8jop4ns5r.cn 拂尘是什么意思hcv9jop1ns4r.cn 酸麻胀痛痒各代表什么qingzhougame.com 韩红是什么民族hcv8jop1ns2r.cn
吃什么有奶hcv9jop6ns6r.cn 为什么脸上长痣越来越多hcv8jop1ns2r.cn 中堂相当于现在什么官hcv8jop7ns9r.cn 心肌劳损的症状是什么hcv8jop9ns7r.cn 言过其实是什么意思hcv9jop0ns0r.cn
百度