feat(doc): add v2 XML content guards for bare ampersands and deprecated tags#822
feat(doc): add v2 XML content guards for bare ampersands and deprecated tags#822herbertliu wants to merge 1 commit intomainfrom
Conversation
…ed tags Add pre-flight checks for the v2 XML document path: - CheckV2XMLBareAmpersand: returns a hard error when content contains a bare & that is not a valid XML entity reference (&, <, >, ', ", &#N;, &#xH;). Such bare ampersands cause the v2 XML parser to reject the request. - CheckV2XMLWarnings: returns non-fatal warnings for two silently-wrong constructs — <quote-container> (v2 drops it; use <blockquote>) and <column width="N"> with an integer value (has no effect; use width-ratio="0.N"). Both checks are integrated into validateCreateV2/validateUpdateV2 (hard error) and executeCreateV2/executeUpdateV2 (warnings to stderr). Only fires when --doc-format is xml (the default).
📝 WalkthroughWalkthroughThis PR adds XML content validation for v2 documents. Two new validators detect bare ampersands (fatal errors) and unsupported v2 constructs (non-fatal warnings). Both create and update v2 command paths now validate XML content and emit warnings before performing API operations. ChangesXML V2 Validation and Warning System
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@shortcuts/doc/docs_update_check.go`:
- Around line 313-317: The current regex columnIntWidthRe is too permissive and
misses valid forms; change it to require a preceding whitespace before the
attribute, allow optional spaces around '=', accept single or double quotes, and
capture the integer value (e.g. `<column\b[^>]*\swidth\s*=\s*(['"])(\d+)\1`) so
it won't match attributes like data-width and will match forms like width='50'
or width = "50". Apply the same tightening to the other related regex defined
around lines 335-341 so both matchers use `\swidth\s*=\s*(['"])(\d+)\1` (or the
float equivalent) and keep the surrounding `<column\b[^>]*` context to limit
matches to column elements.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: bc2981b2-3f9c-4a87-909d-8b36a95bd73c
📒 Files selected for processing (4)
shortcuts/doc/docs_create_v2.goshortcuts/doc/docs_update_check.goshortcuts/doc/docs_update_check_test.goshortcuts/doc/docs_update_v2.go
| // columnIntWidthRe matches a <column … width="N" …> attribute where N is a | ||
| // plain integer. In v2 XML the valid attribute is width-ratio (a float 0–1), | ||
| // not width. An integer width silently has no effect on column sizing. | ||
| var columnIntWidthRe = regexp.MustCompile(`<column\b[^>]*\bwidth="(\d+)"`) | ||
|
|
There was a problem hiding this comment.
Tighten warning matchers to avoid false positives and missed matches.
Current matching can misfire (<quote-containerized> or data-width="50") and miss valid XML forms (width='50', width = "50"). That reduces the reliability of the non-fatal guidance this PR introduces.
♻️ Suggested matcher tightening
+var quoteContainerTagRe = regexp.MustCompile(`<quote-container(?:\s|>|/)`)
-var columnIntWidthRe = regexp.MustCompile(`<column\b[^>]*\bwidth="(\d+)"`)
+var columnIntWidthRe = regexp.MustCompile(`<column\b[^>]*\swidth\s*=\s*(['"])\d+\1`)
func CheckV2XMLWarnings(content string) []string {
if content == "" {
return nil
}
var warnings []string
- if strings.Contains(content, "<quote-container") {
+ if quoteContainerTagRe.MatchString(content) {
warnings = append(warnings,
"<quote-container> is not supported in v2 XML and will be silently dropped; "+
"use <blockquote> instead.")
}Also applies to: 335-341
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@shortcuts/doc/docs_update_check.go` around lines 313 - 317, The current regex
columnIntWidthRe is too permissive and misses valid forms; change it to require
a preceding whitespace before the attribute, allow optional spaces around '=',
accept single or double quotes, and capture the integer value (e.g.
`<column\b[^>]*\swidth\s*=\s*(['"])(\d+)\1`) so it won't match attributes like
data-width and will match forms like width='50' or width = "50". Apply the same
tightening to the other related regex defined around lines 335-341 so both
matchers use `\swidth\s*=\s*(['"])(\d+)\1` (or the float equivalent) and keep
the surrounding `<column\b[^>]*` context to limit matches to column elements.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #822 +/- ##
=======================================
Coverage 65.67% 65.67%
=======================================
Files 513 513
Lines 47655 47689 +34
=======================================
+ Hits 31297 31321 +24
- Misses 13652 13660 +8
- Partials 2706 2708 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@a29a8bffb521b4b9446700aede4dd52847207c9c🧩 Skill updatenpx skills add larksuite/cli#feat/docs-v2-xml-content-guard -y -g |
Summary
Add pre-flight static checks for the v2 XML document path to catch two categories of silent failures before the API call is made.
Changes
shortcuts/doc/docs_update_check.go: AddCheckV2XMLBareAmpersand(hard error) andCheckV2XMLWarnings(non-fatal warnings) with table-driven testsshortcuts/doc/docs_create_v2.go: Integrate bare-ampersand check invalidateCreateV2and XML warnings inexecuteCreateV2shortcuts/doc/docs_update_v2.go: Same integration invalidateUpdateV2/executeUpdateV2shortcuts/doc/docs_update_check_test.go: AddTestCheckV2XMLBareAmpersandandTestCheckV2XMLWarningsChecks
CheckV2XMLBareAmpersand— hard error (returned from Validate):&that is not a recognised XML entity (&,<,>,',",&#N;,&#xH;).CheckV2XMLWarnings— non-fatal warnings (printed to stderr before the API call):<quote-container>— v2 silently drops the block; the correct tag is<blockquote>.<column width="N">with an integer value — has no effect in v2; the correct attribute iswidth-ratio="0.5"(float 0–1).Both checks only fire when
--doc-formatisxml(the default).Test Plan
go test ./shortcuts/doc/...— all pass, 66.4% coveragego vet ./...— cleangofmt -l .— cleanSummary by CodeRabbit
Release Notes