Repository navigation
feat: support Server/Data Center tiny links - #284
Conversation
by-ae
left a comment
There was a problem hiding this comment.
Ran this locally at 495baf4: full jest suite passes (48 suites, 1939 tests). I also checked the decoder against an independent encoder written from Atlassian's tiny link scheme (8-byte little-endian id -> base64 -> strip = and trailing A -> /->-, +->_), and it gives back the same codes the tests use: 5110465220 -> xIKbMAE, 5961218939 -> e-tQYwE, 5849804679 -> h__sXAE. So the decoding itself looks right.
Two behaviour changes I noticed while poking at it:
1. Mistyped tiny links now return a made-up page id instead of an error. Any 1-11 char code now decodes, so the redirect/404 path is never reached for them:
https://test.atlassian.net/wiki/x/invalidCode main: throws "Could not resolve page ID from tiny link"
PR: 15537772927206980490
https://test.atlassian.net/wiki/x/abc main: throws
PR: 46953
That's why the existing test had to change invalidCode to invalidTinyCode. A cheap guard in decodeTinyLinkCode would be to re-encode the decoded id and only accept it if it gives back the same code (invalidCode re-encodes to invalidCodc, because the 11th char only carries 4 bits), and/or to reject ids above 0x7fffffffffffffffn since Confluence ids are Java longs. Those would let invalidCode fall through to the redirect again. Short codes like abc can't be told apart from real ones, so that part is probably just accepted.
2. The redirect fallback with a hostless link goes to the REST base. Now that /x/... (starting with /) gets into this branch, an undecodable code is fetched with this.client.get(pageIdOrUrl) (L471), and axios joins it onto baseURL. With a mocked client I see:
extractPageId('/x/aBcDeFgHiJkL') -> GET https://test.atlassian.net/rest/api + /x/aBcDeFgHiJkL
so it asks .../rest/api/x/... rather than https://test.atlassian.net/x/.... Resolving it first with new URL(pageIdOrUrl, this.configuredOrigin()).href (like the pathname match above already does) would send it to the right place. Not a big deal since valid codes never get here, but it means the fallback can't work for the new hostless form.
|
Thanks for this! Decoding the code locally is a nice improvement, since most tiny links won't need a network round-trip anymore. Two things to sort out while you rebase: 1. Conflict with #288 #288 (the fix for #285) just landed on main and touches the same block in 2. Relative paths in the fallback request When the code can't be decoded locally (e.g. 12+ chars), the URL goes straight to
#288's guard will block the first case after the rebase. It will also reject every relative path, though, because Resolving the URL against the configured origin before the check should fix both: const decodedId = decodeTinyLinkCode(tinyLinkMatch[1]);
if (decodedId) {
return decodedId;
}
const absoluteUrl = new URL(pageIdOrUrl, this.configuredOrigin()).href;
this.assertSameOrigin(absoluteUrl);
try {
const response = await this.client.get(absoluteUrl, { /* same options */ });
// ...redirect handling unchangedSince Two tests would be great too: |
|
Rebased onto main after the tiny-link origin fix (#288). The local decoding runs first, so decodable codes never hit the network. For undecodable codes the same-origin check from #288 still runs before the redirect request, and host-less paths ( |
495baf4 to
a9a1e26
Compare
- Recognize tiny links for Confluence Server and Data Center. (ex: `https://wiki.example.com/x/<code>`) - Decode tiny links locally. Codes that cannot be decoded still fall back to resolving the redirect.
a9a1e26 to
21a5f66
Compare
# [2.31.0](v2.30.6...v2.31.0) (2026-10-31) ### Features * support Server/Data Center tiny links ([#284](#284)) ([7ffb799](7ffb799))
|
🎉 This PR is included in version 2.31.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Previously, tiny links for Confluence Server (ex:
https://wiki.example.com/x/<code>) weren't recognized by the tiny URL path. This PR fixes this:/x/<code>Pull Request Template
Description
Brief description of what this PR does.
Type of Change
Testing
Checklist
Screenshots (if applicable)
Add screenshots to help explain your changes.
Additional Context
Add any other context about the pull request here.