Skip to content

fix(h5): accept valid zero and negative location coordinates - #19543

Open
Jarvis636431 wants to merge 1 commit into
NervJS:mainfrom
Jarvis636431:fix/h5-choose-location-coordinates
Open

Jarvis636431 wants to merge 1 commit into
NervJS:mainfrom
Jarvis636431:fix/h5-choose-location-coordinates

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

这个 PR 做了什么?

Fix H5 chooseLocation coordinate validation. Initial coordinates in the southern/western hemisphere were omitted from the map iframe URL, and selecting a point at latitude or longitude 0 incorrectly reported failure.

Use one numeric latitude/longitude range check for both initial coordinates and selected results. Preserve the explicit coord override, cancellation and submitting without a selection.

Adds 27 DOM regression tests covering negative/zero/boundary coordinates, missing and invalid values, map messages, iframe parameters and result callbacks. The original implementation fails 12 cases.

这个 PR 是什么类型?

  • 错误修复 (Bugfix)

这个 PR 涉及以下平台:

  • Web 端(H5)

验证

  • chooseLocation DOM tests: 27 passed.
  • H5 package test:ci: 23 suites / 160 tests passed.
  • ESLint for changed files: passed.
  • H5 package build: passed with Node 20.19.4 / pnpm 10.0.0.

Closes #19542

Summary by CodeRabbit

  • 修复

    • 地图查询仅在经纬度均为有效数字且处于合法范围内时传入坐标;无效或不完整的坐标将被省略。
    • 选点结果采用相同的经纬度校验规则,避免无效坐标被视为有效结果。
    • 显式传入的 coord 可覆盖初始坐标生成的查询参数。
  • 测试

    • 补充对有效、无效及缺失坐标,以及选点成功、失败和取消场景的覆盖。

@coderabbitai

coderabbitai Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 14febc7e-11ed-40ca-8c21-24639658acf5
📥 Commits

Reviewing files that changed from the base of the PR and between 53b9d3f and e04c5dd.

📒 Files selected for processing: 2
  • packages/taro-h5/__tests__/location/chooseLocation.test.ts
  • packages/taro-h5/src/api/location/chooseLocation.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

chooseLocation 现在校验纬度和经度是否为数字且处于有效范围。有效的零值和负值坐标可用于初始化地图及返回选点结果。新增测试覆盖坐标校验、显式 coord、失败和取消场景。

Changes

H5 chooseLocation 坐标处理

层 / 文件 摘要
初始坐标与选点结果校验
packages/taro-h5/src/api/location/chooseLocation.ts, packages/taro-h5/__tests__/location/chooseLocation.test.ts
初始坐标仅在纬度和经度均为数字且处于有效范围时生成 coord。选点结果使用相同规则校验,有效零值坐标可通过。测试覆盖坐标边界、无效坐标、显式 coord 优先、未选点和取消场景。

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to e04c5

Zero and negative in-range coordinates are accepted while invalid coordinates are rejected. No confirmed issue currently blocks merging.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 标题准确概括了主要变更:H5 chooseLocation 支持有效的零坐标和负坐标。标题简洁、明确,并与代码和测试变更一致。
Linked Issues check Passed PR 实现了 #19542 的编码要求。isValidCoordinates 要求纬度为数字且在 [-90, 90],经度为数字且在 [-180, 180];比较结果也会排除 NaN 和 Infinity。相同检查用于初始 iframe coord 参数和选点结果,因此支持负数、零值和边界值,并拒绝缺失、非有限及越界值。...opts 仍保留显式 mapOpts.coord 覆盖。…
Out of Scope Changes check Passed 变更范围与 #19542 直接相关。生产代码只调整 H5 chooseLocation 的坐标校验。新增测试只验证该 API 的坐标、iframe 参数、消息结果、回调、取消和未选点行为。未发现无关的功能或文件变更。
Full details: Linked Issues check

Explanation

PR 实现了 #19542 的编码要求。isValidCoordinates 要求纬度为数字且在 [-90, 90],经度为数字且在 [-180, 180];比较结果也会排除 NaN 和 Infinity。相同检查用于初始 iframe coord 参数和选点结果,因此支持负数、零值和边界值,并拒绝缺失、非有限及越界值。...opts 仍保留显式 mapOpts.coord 覆盖。测试覆盖初始 URL、选点成功与失败、回调、取消和未选点提交。

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/taro-h5/__tests__/location/chooseLocation.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/taro-h5/src/api/location/chooseLocation.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).

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.

❤️ Share

我是小兔,绕过经线与纬线,
看零度坐标也能安然通过。
南行西行,地图照常载入,
选中地点,名称地址一并返回。
若坐标越界,我便轻轻摇头。

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 55.82%. Comparing base (53b9d3f) to head (e04c5dd).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #19543      +/-   ##
==========================================
+ Coverage   55.60%   55.82%   +0.21%     
==========================================
  Files         467      467              
  Lines       25659    25662       +3     
  Branches     6416     6440      +24     
==========================================
+ Hits        14268    14326      +58     
- Misses       9399     9455      +56     
+ Partials     1992     1881     -111     
Flag Coverage Δ
taro-cli 60.27% <ø> (ø)
taro-runtime 58.78% <ø> (ø)
taro-web 60.28% <100.00%> (+1.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ackages/taro-h5/src/api/location/chooseLocation.ts 96.87% <100.00%> (+88.67%) ⬆️

... and 42 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: H5 chooseLocation rejects zero coordinates and omits negative initial coordinates

1 participant