用一个更严格的正则表达式来把 .method(
替换为 ._c("method")(
#139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
我改了什么?
我把
\.\s*(\w+)\s*\(
换成了(?<!\\)\.\s*(\w+)\s*\(
,意思是在匹配.method(
的同时,不匹配\.method(
。原来有什么问题?
我需要用 JSPatch 来在 webview 中 evaluate 一段 js 代码,但是这段代码符合替换的条件,所以也被替换了,造成了 JSPatch 的脚本本身有语法错误。
改动后,1、要求 webview 需要执行的 js 脚本里的
.method
都写成\.method
。2、正则表达式也如这个 PR 这样改过。于是达到了效果:为什么这么改?
思考后,我发现要改正这个 bug,有三种办法。
找到一个正确的正则表达式,只匹配字符串以外的
.method(
。于是学艺不精,没有找到 >.< 情况实在太复杂了,还是希望有人能研究出来。
在 webview 要执行的 js 代码里做 hack,用别的字符代替
.
,运行时再替换回来。比如:
显然,太 hacky 了,对写 patch 的同学来说真是……
两边都改。javascript string 里用
\.
代替.
本身就合法。相对应的,替换的正则表达式的改动也很小,情况变得很简单,也不影响旧版本。新的正则表达式只要确认原来匹配的方法前,没有\
出现。所以希望……