Re: [問題] 相對路徑....
※ 引述《qayqay (oh my god)》之銘言:
: http://maxtellyou.blogspot.com/2012/03/blog-post.html
: 網址裡的相對路徑 ..../../ = ./ 但 ../..../ 不等於 ..../../
: .../../ = ..../../
: ※ 引述《qayqay (oh my god)》之銘言:
: : 例
: : http://A/B/C/index.asp
: : 其中html 有
: : <img src="../images/space.gif" alt="" />
: : 這個比較沒問題 瀏覽器解出來 是http://A/B/images/space.gif

: : <img alt="*" src="../..../../df_sys/df_img/arr.gif" />
: : 瀏覽器解出來 是http://A/B/df_sys/df_img/arr.gif

: : WHY?
ref: http://tools.ietf.org/html/rfc3986#page-33
FRC3986 page 33-34
主要看第 34 頁的 merge path 過程
example:
1 : /a/b/c/./../../g
2E: /a /b/c/./../../g
2E: /a/b /c/./../../g
2E: /a/b/c /./../../g
2B: /a/b/c /../../g
2C: /a/b /../g
2C: /a /g
2E: /a/g
在處理 dot 的過程就是 remove dot segments
而在這過程中主要移除的有 .(單點) 跟 ..(雙點)
在 5.2.4 中的 處理第二步是針對 dot 做改變路徑的動作
所以以 blog 中的例子來說
假設目前網址為 www.sample.com/www/image/show.html
所以資料夾路徑為 www.sample.com/www/image/
實際圖片路徑則為 www.sample.com/www/test2.jpg
那第一個
<img src="../test2.jpg">
會先跳回上一頁,再找到test2.jpg
output buf input buf
----------------------------------------------
>> ../test2.jpg(跳回上一層)
>> www.sample.com/www /test2.jpg (找 test2.jpg)
>> www.sample.com/www/test2.jpg
而第二個例子會找不到的原因是實際網址會變成
output buf input buf
----------------------------------------------
>> ../../..../test2.jpg(往上一層)
>> www.sample.com/www /../..../test2.jpg(再往上一層)
>> www.sample.com /..../test2.jpg (前往....資料夾)
>> www.sample.com/.... /test2.jpg (找 test.jpg)
>> www.sample.com/..../test2.jpg
而第三第四網址則是如下
output buf input buf
----------------------------------------------
>> ..../../../test2.jpg
>> www.sample.com/www/image/.... /../../test2.jpg
>> www.sample.com/www/image /../test2.jpg
>> www.sample.com/www /test2.jpg
>> www.sample.com/www/test2.jpg
output buf input buf
----------------------------------------------
>> ../..../../test2.jpg (往上一層)
>> www.sample.com/www /..../../test2.jpg (找....資料夾)
>> www.sample.com/www/.... /../test2.jpg (往上一層)
>> www.sample.com/www /test2.jpg (找test.jpg)
>> www.sample.com/www/test2.jpg
因此如果按照這種規則下去跑
如果你的 dot 想寫超過四個也沒問題
ex:
<img src="../.....././../..../././../test2.jpg" />
這樣應該也是可以找到正確的圖片~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.34.30.6
→
03/19 12:29, , 1F
03/19 12:29, 1F
→
03/19 12:29, , 2F
03/19 12:29, 2F
推
03/19 13:05, , 3F
03/19 13:05, 3F
→
03/19 13:13, , 4F
03/19 13:13, 4F
→
03/19 13:13, , 5F
03/19 13:13, 5F
*改小錯誤
推
03/19 14:07, , 6F
03/19 14:07, 6F
上色完畢Orz 希望沒錯,不太會上
※ 編輯: kerash 來自: 114.34.30.6 (03/19 14:21)
推
03/19 14:15, , 7F
03/19 14:15, 7F
推
03/19 15:24, , 8F
03/19 15:24, 8F
討論串 (同標題文章)