feat(redirect-links): stage util to append ?u= on openhm.xyz URLs (#1164)#1184
feat(redirect-links): stage util to append ?u= on openhm.xyz URLs (#1164)#1184oxoxDev wants to merge 5 commits intotinyhumansai:mainfrom
Conversation
…inyhumansai#1164) Adds append_user_id_to_public_links + rewrite_outbound_for_user wrapper. Util-only — no call sites yet; wire-up follows once openhm.xyz emission lands client-side. Regex anchored on https?:// (rejects evil-openhm.xyz / openhm.xyz.evil.com), idempotent (skips URLs already containing u=), preserves existing query strings, urlencoding::encode for special chars in user_id. 9 inline test cases. Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…yhumansai#1164) Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…mansai#1164) Asserts the wrapper expands openhuman:// placeholders AND tags public openhm.xyz URLs with ?u= when user_id is Some, and leaves URLs untagged when user_id is None. Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds two exported functions that expand internal link placeholders then append a URL-encoded ChangesUser ID Tagging for Public Links
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Review rate limit: 3/5 reviews remaining, refill in 14 minutes and 1 second. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/openhuman/redirect_links/ops.rs`:
- Around line 34-35: The regex used to match URLs (Regex::new(...) in ops.rs)
currently includes '#' in the query character class, causing appended "u=" to
become part of the fragment for URLs like https://openhm.xyz/abc?foo=bar#frag;
update the regex to exclude '#' from the query charclass (remove '#' from the
class string) and change the tail-appending logic (the code that concatenates
the new param in the block around lines 165–170) to split the matched tail on
'#' into query and fragment parts, insert the "u=..." into the query portion
(adding '?' or '&' as appropriate) and then rejoin with the fragment prefixed by
'#' so the u param is always a query parameter, not part of the fragment.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 394c4d2b-b469-4d8a-8a09-3d1e5de50156
📒 Files selected for processing (2)
src/openhuman/redirect_links/mod.rssrc/openhuman/redirect_links/ops.rs
594d1bf to
2196f97
Compare
…i#1164) CI cargo fmt --check flagged the single-line assert! at ops.rs:417 — wrap in multi-line form per rustfmt rules. Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
…ansai#1164) CodeRabbit feedback: regex put '#' in the query class, so URLs like https://openhm.xyz/abc?foo=bar#frag had ?u= appended after the fragment, making u= fragment data instead of a query parameter. Split the matched URL on '#' so the user-id always lands in the query, then re-attach the fragment after. Two new tests cover bare+fragment and query+fragment. Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com>
Summary
Stage a rust util that appends
?u=<user_id>to everyopenhm.xyz/<id>URL in a string. Util-only — no call sites yet; the wire-up belongs in a follow-up onceopenhm.xyzURL emission lands client-side (today the repo only emits internalopenhuman://link/<id>).Problem
Per #1164, every public
openhm.xyz/<id>short URL surfaced to the user must carry?u=<user_id>so the redirect service can attribute clicks and resolve user-scoped state. Todaygrep -rn "openhm.xyz" src/returns no hits — the public form is produced backend-side. This PR puts the rewrite logic in place so wiring it from a future caller is one line.Solution
append_user_id_to_public_links(text, Option<user_id>) -> Stringinsrc/openhuman/redirect_links/ops.rs— regex-based, idempotent, URL-encodesuser_id, preserves existing query strings, anchored onhttps?://so lookalike domains (evil-openhm.xyz,openhm.xyz.evil.com) do not match.rewrite_outbound_for_user(config, text, Option<user_id>)— convenience wrapper running the existingrewrite_outboundthen injecting?u=.redirect_links::mod.#[cfg(test)]cases cover bare URL, existing query, idempotent,Noneuser, no-URL, multi-URL, special-char encoding, lookalike rejection, surrounding text/punctuation, and the wrapper roundtrip.Submission Checklist
ops.rscargo check,cargo fmt --check,cargo clippyclean forredirect_linkscargo test --lib redirect_linksgreen (27 pass)pnpmgates applyImpact
Zero runtime impact today (no caller). Stages the substitution layer so a future backend or follow-up PR can wrap outbound text in one call.
Related
Closes #1164. Wire-up deferred to follow-up — confirm with @senamakel whether
?u=injection should land render-time (here) or resolve-time (server-side at openhm.xyz).Summary by CodeRabbit