Skip to content

[v1.3] fix #1235#1238

Open
cyfung1031 wants to merge 7 commits intoscriptscat:release/v1.3from
cyfung1031:fix-link-decoding004
Open

[v1.3] fix #1235#1238
cyfung1031 wants to merge 7 commits intoscriptscat:release/v1.3from
cyfung1031:fix-link-decoding004

Conversation

@cyfung1031
Copy link
Collaborator

@cyfung1031 cyfung1031 commented Feb 13, 2026

通用代码修正问题
不针对单一平台

searchParams.get("uuid") 只用作判断有无
实际值用 location.search 经判断后取 rawUrl

如 url 被 encodeURIComponent (双重编码), 则解码
否则直接使用


Testing


Case 1

Case 2




@cyfung1031 cyfung1031 mentioned this pull request Feb 13, 2026
@cyfung1031 cyfung1031 changed the title fix #1235 [v1.3] fix #1235 Feb 13, 2026
@CodFrm
Copy link
Member

CodFrm commented Feb 13, 2026

不需要针对GreasyFork、SleazyFork特殊处理呀,如果其他平台,也搞个有问题的url不可能也去特殊处理啊,这个bug产生的原因是 searchParams 取的url参数有问题,换成location保持原本的值去fetch脚本数据就可以了,prettyUrl #1236 的看起来没啥问题

const url = searchParams.get("url");

@cyfung1031
Copy link
Collaborator Author

不需要针对GreasyFork、SleazyFork特殊处理呀,这个bug产生的原因是 searchParams 取的url参数有问题

  1. chrome declarative rule 的 regexSubstitution 不会进行 encodeURI / encodeURIComponent 等预处理。chrome会把解码的原始url放在 \1
  2. 在install页面看到的是一般 url 的 encodeURI 处理过的东西 (这里假设了 chrome 现时版本 143. 这PR写的是通用方式针对 Firefox 及未来Chrome)
  3. 我在这加了处理能让 install页面取得原本的原始网址
  4. GF和SF的档案名是用encodeURIComponent. 所以不能直接 new URL.

之前的 toEncodedURL是把原始网址正确编码
但你不喜欢,我就不再这里纠缠了
只需理GF和SF

prettyUrl 更不是我写的。我没有责任让它完善

@CodFrm
Copy link
Member

CodFrm commented Feb 13, 2026

怎么感觉搞反了呢,我是觉得不需要特殊处理,prettyUrl可以(另外这个是你写的#993,当然这个无所谓啦)

@cyfung1031
Copy link
Collaborator Author

(另外这个是你写的https://github.com/scriptscat/scriptcat/pull/993,当然这个无所谓啦)

呀。我失忆了。对不起
完全没印象

怎么感觉搞反了呢,我是觉得不需要特殊处理

对于问题,我提出了例子,提出了解决用的代码,提出了见解
也接受了你在 1236 的指责。bug 修补以外的都拿走

你是作者,接不接受在于你

@cyfung1031 cyfung1031 added the hotfix 需要尽快更新到扩展商店 label Feb 13, 2026
@cyfung1031
Copy link
Collaborator Author

cyfung1031 commented Feb 14, 2026

为什么变成特殊处理?

首先 GF 可以把 % + 写在档名
% 是 URL全体编码时变 "%25"
+ 是 URL参数编码时变 "%2B"
但GF内部会把 + 也变成 "%2B"

因此浏览器在读网址时,虽然看到的解码是 % 跟 +,但这个网址用正常编码的话,会对不上实际网址
在 chrome declarative rule 的 regexSubstitution ,chrome 放的是看得到的网址,即已经没有 %25 %2B. 因为它是用在网址的regexSubstitution,它会把这部份做正常的「 URL全体编码」,也就是 「% 变 "%25" + 不变」的情况。

这PR我加的代码是用来取 「chrome 看得到的网址」 <- 这个我视为通用处理
正常用这个可以直接发起 fetch request. 内部会自行处理编码

很可惜,用这个 URL 的话, GF就会返回403 < 所以需要特殊处理让它变回 "%25" 跟 "%2B"
这是GF本身的问题。我数日前反映了,但Jason不理。

@CodFrm
Copy link
Member

CodFrm commented Feb 14, 2026

为什么不特殊处理

  1. 如果出现其它平台有另外的规则,或者gf换了另外的规则,那么这套东西就失效了,也不可能针对每个特殊规则去处理
  2. fetch时使用原本的url才是合理,不管它编码是不是正常,能不能访问

这个bug是因为之前使用的searchParams获取url,searchParams获取到的内容是处理过的,他里面包含了decode的逻辑导致url少了,使用location.href即可解决,我不太明白你特殊处理想解决什么问题

如果平台提供了一个错误的url导致403那是平台的问题,如果平台提供了一个编码错误,但是可以正常访问的url,那不关我们的事

@cyfung1031
Copy link
Collaborator Author

我重新检视了我的改动。的确可以做得更通用不用考虑单一平台。我再改一下

@cyfung1031 cyfung1031 marked this pull request as draft February 14, 2026 09:23
@cyfung1031
Copy link
Collaborator Author

fetch时使用原本的url才是合理,不管它编码是不是正常,能不能访问

处理完成
通用了

@cyfung1031 cyfung1031 marked this pull request as ready for review February 14, 2026 10:00
@cyfung1031 cyfung1031 linked an issue Feb 14, 2026 that may be closed by this pull request
type: "redirect" as chrome.declarativeNetRequest.RuleActionType,
redirect: {
regexSubstitution: `${installPageURL}?url=\\1`,
regexSubstitution: `${installPageURL}?url=___,\\1,___`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不需要__标记,处理端直接取url=后面全部的内容即可,地址框展示也友好一些

Copy link
Collaborator Author

@cyfung1031 cyfung1031 Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要标记。可能会有双重编码。还未在Firefox测试。先保留

地址框展示也友好一些

d1a2a1a 在这修好了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

呀。有方法不加标记判断. 我改

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用标记了

});

const loadURLAsync = async (urlHref: string) => {
const loadURLAsync = async (candidateUrls: string[]) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外部实际只传一个数组成员 不需要数组了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以。我改一下

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改了

if ((m = /\burl=___,(.+),___(.*)$/.exec(location.search))) {
// without component encoding (Chrome's current spec)
// "/src/install.html?url=___,https://update.greasyfork.org/scripts/1234/ABC%20DEF%20GHK%20%2B%2B.user.js,___?a=12&b=34"
rawUrl = `${m[1]}${m[2]}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

什么情况会有这种url,后面是用户自己编辑的?所以感觉更不要加这个分割标记符了

This comment was marked as outdated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用标记了

@cyfung1031 cyfung1031 marked this pull request as draft February 14, 2026 10:37
@cyfung1031 cyfung1031 marked this pull request as ready for review February 14, 2026 10:46
// without component encoding (Chrome's current MV3 spec)
// "/src/install.html?url=___,https://update.greasyfork.org/scripts/1234/ABC%20DEF%20GHK%20%2B%2B.user.js,___?a=12&b=34"
rawUrl = m[1];
} else if ((m = /\burl=([\w-]*%.+)$/.exec(location.search))) {
Copy link
Member

@CodFrm CodFrm Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

会有这种情况吗?我感觉Firefox也不会呀,多虑了

DNR也是重定向,按理来说不应该会再次编码的,如果编码了,重定向那就是个错误的重定向,算浏览器bug了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

先这样吧
日后MV3可能会改
因为 ?url=\1 这个写法应该要把 内容编码, 但现在MV3没有

多虑是多虑,但这些代码写一次就不想再改
也不是多了多少代码

Copy link
Member

@CodFrm CodFrm Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果表达式是 \1&param=xxx 编码了,那会出大问题,从这个DNR设计上就不应该编码,不喜欢因为没有的甚至几乎不可能出现的情况增加多余的代码

Copy link
Collaborator Author

@cyfung1031 cyfung1031 Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那你当作用户可以在网址栏输入 https://update.greasyfork.org/scripts/519037/Nexus%20No%20Wait%20++.user.js
https%3A%2F%2Fupdate.greasyfork.org%2Fscripts%2F519037%2FNexus%2520No%2520Wait%2520%2B%2B.user.js

没编码的不合法param 不能直接用 useSearchParams 取得
所以还是要转一下
日后还可能会有一些 option 吧
不转的话, url param 就只能用 不合法的单一 url
现在做法是,DNR 传来了后就编码一下。

  useEffect(() => {
    if (urlHref) {
      setSearchParams(
        (prev) => {
          return prev.get("url") !== urlHref ? new URLSearchParams(`?url=${urlHref}`) : prev;
        },
        { replace: true }
      );
    }
  }, [setSearchParams, urlHref]);

就是让正确有编码的塞回网址列

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

说实话。。。。用户也几乎不可能去做这个,更不可能会复制编码后的url,不要总是编造场景

Copy link
Member

@CodFrm CodFrm Feb 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

区分出合法参数 和不合法参数. 不合法参数 就要处理呀

这个代码它可以区分两者,然后把正确参数塞回网址

有什么不好呢

代码被这个 非法url 参数 锁死的话,日后要加参数就麻烦了

因为不可能存在的场景,不喜欢做多余的处理

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果表达式是 \1&param=xxx 编码了,那会出大问题,从这个DNR设计上就不应该编码,不喜欢因为没有的甚至几乎不可能出现的情况增加多余的代码

MV3 的标准一直在更新
如果日后突然不能使用
大家又会一直发 issue
和MV3相关的,做的全面点会较好

我的怀疑也很合理。现在没有写明是怎么编码。
没写明就能随时改变

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我说服不了你就算了。你改代码 merge了算了。我不想把写好的改成写不好的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果表达式是 \1&param=xxx 编码了,那会出大问题,从这个DNR设计上就不应该编码,不喜欢因为没有的甚至几乎不可能出现的情况增加多余的代码

MV3 的标准一直在更新

如果日后突然不能使用

大家又会一直发 issue

和MV3相关的,做的全面点会较好

我的怀疑也很合理。现在没有写明是怎么编码。

没写明就能随时改变

不可能随意改变的,而且改变后 \1&param 这种情况会出问题,影响的不止我们,如果按照这个思路,任何东西都可能改变,任何功能都可能因为改变不可用。如果发生几率大一点还就算了,几乎不可能发生的事情

别纠结了,按我说的吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我说服不了你就算了。你改代码 merge了算了。我不想把写好的改成写不好的

好不好是主观的,我认为是多余的代码,所以我认为不好

说服不了对方,也没有影响功能,按我的来吧。我回家改,现在我用的GitHub mobile

@cyfung1031 cyfung1031 requested a review from CodFrm February 14, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix 需要尽快更新到扩展商店

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] GreasyFork Install - Fetch error 403

2 participants