Can I use require(“path”).join to safely concatenate urls?

前端 未结 15 564
臣服心动
臣服心动 2020-12-23 13:06

Is this safe to use require(\"path\").join to concatenate URLs, for example:

require(\"path\").join(\"http://example.com\", \"ok\"); 
//returns          


        
15条回答
  •  清歌不尽
    2020-12-23 13:25

    No! On Windows path.join will join with backslashes. HTTP urls are always forward slashes.

    How about

    > ["posts", "2013"].join("/")
    'posts/2013'
    

提交回复
热议问题