Enhance SYLink processing for improved plugin and block handling - #17843
Merged
Vanessa219 merged 6 commits intoJun 22, 2026
Conversation
Zuoqiu-Yingyi
marked this pull request as ready for review
June 11, 2026 09:48
Contributor
7 tasks
Contributor
Author
|
@Vanessa219 |
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors processSYLink in app/src/editor/openLink.ts to improve routing/handling of siyuan:// URLs, especially for blocks and plugins hosts, and to fix correctness issues in plugin URL parsing/matching.
Changes:
- Reorganizes protocol handling into
switch (urlObj.hostname)with explicit"blocks"and"plugins"cases. - Tightens plugin matching for
siyuan://plugins/...by using exact name equality and URL-decoding the path segment. - Refactors custom-tab data parsing to an IIFE and improves failure handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ved functionality
Contributor
Author
|
@Vanessa219 |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
Author
|
@Vanessa219 |
Zuoqiu-Yingyi
marked this pull request as draft
June 13, 2026 10:51
Contributor
Author
|
原有实现存在循环依赖问题, 需要重构
|
…d update related parsing function for consistency
Zuoqiu-Yingyi
marked this pull request as ready for review
June 17, 2026 03:57
Contributor
Author
|
@Vanessa219
|
Member
Contributor
Author
@Vanessa219 siyuan/app/src/editor/openLink.ts Line 65 in 96dfe0b siyuan/app/src/util/pathName.ts Line 45 in 96dfe0b |
Member
Member
|
3.7.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.



Description / 描述
English
Refactors SiYuan protocol URL handling across app/src/editor/openLink.ts and app/src/util/pathName.ts.
New utility:
parseSiYuanUriBlockInfo(url)inpathName.ts— a single, tested parser that handles bothsiyuan:andweb+siyuan:block URLs and returns a typedISiYuanUriBlockInfoobject (ornull). Replaces the ad-hoc substring/regex extraction that was duplicated acrossgetIdZoomInByPathandprocessSYLink.Bugs fixed:
Plugin name matching was too loose — the old code used
startsWith(plugin.name)to find the target plugin, which would incorrectly match a plugin whose name is a prefix of another (e.g.plugin-abcmatching againstplugin-abcdef). The new code uses exact equality (=== plugin.name).Plugin name/tab-type segment was not URL-decoded — the pathname segment was used as-is without calling
decodeURIComponent, causing matching to fail for plugin names containing percent-encoded characters. Error handling is added for malformed sequences.processSYLinkrejectedweb+siyuan:URLs — onlysiyuan:was accepted. The protocol check is now unified withparseSiYuanUriBlockInfo.Circular dependency —
openByMobilewas defined inprotyle/util/compatibility.ts, which importedprocessSYLinkfromeditor/openLink.ts(under#if MOBILE); meanwhileopenLink.tsimportedopenByMobileback fromcompatibility.ts, forming a cycle:The fix moves
openByMobileintoeditor/openLink.tsand removes theprocessSYLinkimport fromcompatibility.ts. All downstream consumers (protyle/preview/index.ts,menus/commonMenuItem.ts,plugin/platformUtils.ts) are updated to importopenByMobilefrom its new location.Other improvements:
processSiYuanUriBlocksandprocessSiYuanUriPluginsas standalone exported functions.getIdZoomInByPathto useparseSiYuanUriBlockInfo, removing duplicated substring-offset arithmetic.ISiYuanUriBlockInfointerface totypes/index.d.ts.import {App}toimport type {App}inopenLink.tsto break a type-level cycle throughindex.ts→boot/onGetConfig.ts→openLink.ts.中文
重构 app/src/editor/openLink.ts 与 app/src/util/pathName.ts 中的思源协议 URL 处理逻辑。
新增工具函数:
pathName.ts中新增parseSiYuanUriBlockInfo(url)——统一解析siyuan:和web+siyuan:两种协议的块链接,返回类型化的ISiYuanUriBlockInfo对象(或null)。替换了原先分散在getIdZoomInByPath与processSYLink中重复的字符串偏移/正则提取逻辑。缺陷修复:
插件名匹配过于宽松 — 旧代码使用
startsWith(plugin.name),当某个插件名是另一个插件名的前缀时会产生误匹配(如plugin-abc错误匹配plugin-abcdef)。新代码改用精确相等(=== plugin.name)。插件名/页签类型片段未进行 URL 解码 — 旧代码直接使用原始路径片段而未调用
decodeURIComponent,导致插件名含百分号编码字符时匹配失败。新代码增加了对畸形编码序列的错误处理。processSYLink不支持web+siyuan:协议 — 旧代码只接受siyuan:,协议校验现已与parseSiYuanUriBlockInfo统一。循环依赖 —
openByMobile定义在protyle/util/compatibility.ts中,该文件在#if MOBILE条件下从editor/openLink.ts导入processSYLink;而openLink.ts又从compatibility.ts导入openByMobile,形成循环:修复方式:将
openByMobile移入editor/openLink.ts,并从compatibility.ts中移除processSYLink的导入。所有下游消费方(protyle/preview/index.ts、menus/commonMenuItem.ts、plugin/platformUtils.ts)均已更新为从新位置导入openByMobile。其他改进:
processSiYuanUriBlocks和processSiYuanUriPlugins提取为独立的可导出函数。getIdZoomInByPath,改用parseSiYuanUriBlockInfo,消除了硬编码的字符串偏移量计算。types/index.d.ts中新增ISiYuanUriBlockInfo接口。openLink.ts中的import {App}改为import type {App},打破通过index.ts→boot/onGetConfig.ts→openLink.ts的类型级循环。Type of change / 变更类型
缺陷修复
代码重构
新功能
修改文案或增加新语言
Checklist / 检查清单
我对自己的代码进行了自我审查
我拥有所提交代码的完整权利,并同意其以本项目的 AGPL-3.0 许可证授权
devbranch and has no merge conflictsPR 提交到
dev分支,并且没有合并冲突