react-native 完成实现URL访问器,如主机、主机名、用户名、密码

oyt4ldly  于 4个月前  发布在  React
关注(0)|答案(6)|浏览(102)

描述

window.URL对象在Hermes中可用,但其他实现未实现。所有访问器都有错误。
react-native/packages/react-native/Libraries/Blob/URL.js
第140行到第230行
| | constructor(url: string,base: string|URL){ |
| | letbaseUrl=null; |
| | if(!base||validateBaseUrl(url)){ |
| | this._url=url; |
| | if(!this._url.endsWith('/')){ |
| | this._url+='/'; |
| | } |
| | }else{ |
| | if(typeofbase==='string'){ |
| | baseUrl=base; |
| | if(!validateBaseUrl(baseUrl)){ |
| | thrownewTypeError(Invalid base URL: ${baseUrl}); |
| | } |
| | }else{ |
| | baseUrl=base.toString(); |
| | } |
| | if(baseUrl.endsWith('/')){ |
| | baseUrl=baseUrl.slice(0,baseUrl.length-1); |
| | } |
| | if(!url.startsWith('/')){ |
| | url=/${url}; |
| | } |
| | if(baseUrl.endsWith(url)){ |
| | url=''; |
| | } |
| | this._url=${baseUrl}${url}; |
| | } |
| | } |
| | gethash(): string{ |
| | thrownewError('URL.hash is not implemented'); |
| | } |
| | gethost(): string{ |
| | thrownewError('URL.host is not implemented'); |
| | } |
| | gethostname(): string{ |
| | thrownewError('URL.hostname is not implemented'); |
| | } |
| | gethref(): string{ |
| | returnthis.toString(); |
| | } |
| | getorigin(): string{ |
| | thrownewError('URL.origin is not implemented'); |
| | } |
| | getpassword(): string{ |
| | thrownewError('URL.password is not implemented'); |
| | } |
| | getpathname(): string{ |
| // ...省略部分代码...//

const urlObj = new window.URL( validUrlString );
urlObj.hostname
// Error: URL.hostname is not implemented

|

const urlObj = new window.URL( validUrlString );
urlObj.hostname
// Error: URL.hostname is not implemented

如何重现问题?

const urlObj = new window.URL( validUrlString );
urlObj.hostname
// Error: URL.hostname is not implemented

React Native版本

0.73.6

受影响的平台

运行时-Android

Reproducible on all systems. The code has a baked-in Error and no implementation.

输出

This error is located at:
    in SecureContext (created by Connect(SecureContext))
    in Connect(SecureContext) (created by App)
    in RCTView (created by View)
    in View (created by App)
    in App (created by RenderApp)
    in Provider (created by RenderApp)
    in RenderApp
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in app(RootComponent), js engine: hermes

堆栈跟踪或日志x1a3b1x无法在浏览器中重现,只能在hermes/Android上看到,因此这无关紧要。x1a4b1x截图和视频无响应

gj3fmq9x

gj3fmq9x1#

⚠️React Native的新版本可用!
i️您正在使用受支持的次要版本,但似乎有一个更新的补丁可用 - 0.73.8。请升级到您次要版本的最高补丁或最新版本,并验证问题是否仍然存在(或者,创建一个新项目并在其中重现问题)。如果无法重现,请告知我们,以便我们关闭此问题。这有助于确保我们关注仍在最近版本中存在的问题。
epfja78i

epfja78i2#

⚠️ React Native的新版本可用!
i️ 您当前使用的是受支持的次要版本,但似乎有一个更新的补丁可用 - 0.73.8。请升级。
这是最新版本的代码,显示功能尚未实现。
react-native/packages/react-native/Libraries/Blob/URL.js
第169行到第219行 4cee0a4
| | gethash(): string{ |
| | thrownewError('URL.hash is not implemented'); |
| | } |
| | |
| | gethost(): string{ |
| | thrownewError('URL.host is not implemented'); |
| | } |
| | |
| | gethostname(): string{ |
| | thrownewError('URL.hostname is not implemented'); |
| | } |
| | |
| | gethref(): string{ |
| | returnthis.toString(); |
| | } |
| | |
| | getorigin(): string{ |
| | thrownewError('URL.origin is not implemented'); |
| | } |
| | |
| | getpassword(): string{ |
| | thrownewError('URL.password is not implemented'); |
| | } |
| | |
| | getpathname(): string{ |
| | thrownewError('URL.pathname not implemented'); |
| | } |
| | |
| | getport(): string{ |
| | thrownewError('URL.port is not implemented'); |
| | } |
| | |
| | getprotocol(): string{ |
| | thrownewError('URL.protocol is not implemented'); |
| | } |
| | |
| | getsearch(): string{ |
| | thrownewError('URL.search is not implemented'); |
| | } |
| | |
| | getsearchParams(): URLSearchParams{ |
| | if(this._searchParamsInstance==null){ |
| | this._searchParamsInstance=newURLSearchParams(); |
| | } |
| | returnthis._searchParamsInstance; |
| | } |
| | |
| | toJSON(): string{ |
| // 请升级。

dfty9e19

dfty9e193#

你好,我是sossost,一个新贡献者。我可以尝试解决这个问题吗?

m3eecexj

m3eecexj5#

你好,我是Shivanand,新的贡献者。我可以尝试解决这个问题吗?请提供有关此问题的简要信息。

9nvpjoqh

9nvpjoqh6#

嘿,我几天前学了JS和版本控制,我愿意贡献...我不知道如何开始...有人能帮我吗?

相关问题