-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(useRouter): 新增query参数 #51
Conversation
WalkthroughThis pull request introduces a new dependency, Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant R as Router Module
participant Q as fast-querystring
U->>R: Call navigateTo(options with query)
R->>R: Invoke buildUrl() function to process query
R->>Q: qs.stringify(query)
Q-->>R: Return serialized query string
R->>R: Construct final URL with query parameters
R-->>U: Execute navigation with updated URL
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/useRouter/index.ts (1)
97-109
: Add input validation for URL and query parameters.While the function handles basic cases well, consider adding:
- URL validation to prevent malformed URLs
- Sanitization of query values to handle null/undefined
function buildUrl(url: LocationUrl, query?: LocationQueryRaw) { + if (typeof url !== 'string' || !url.trim()) { + throw new Error('Invalid URL provided'); + } + + // Sanitize query values + const sanitizedQuery = query ? Object.fromEntries( + Object.entries(query).filter(([_, v]) => v != null) + ) : undefined; + - if (!query) { + if (!sanitizedQuery) { return url; } - const serializedQuery = qs.stringify(query); + const serializedQuery = qs.stringify(sanitizedQuery);src/useRouter/index.md (1)
43-47
: Comprehensive documentation with clear examples!The documentation effectively explains the query parameter feature and includes important notes about serialization and encoding. Consider adding examples for:
- Complex object serialization behavior
- URL encoding of special characters
Add these examples to better illustrate the behavior:
router.navigate({ url: '/pages/topics/index?c=1', query: { a: 1, b: 2 } }); // => /pages/topics/index?c=1&a=1&b=2 +// Complex objects are serialized +router.navigate({ url: '/page', query: { obj: { x: 1 } } }); // => /page?obj=%7B%22x%22%3A1%7D +// Special characters are encoded +router.navigate({ url: '/page', query: { text: '你好' } }); // => /page?text=%E4%BD%A0%E5%A5%BD
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
package.json
(1 hunks)src/useRouter/index.md
(1 hunks)src/useRouter/index.ts
(3 hunks)
🔇 Additional comments (4)
src/useRouter/index.ts (3)
83-89
: Well-structured type definitions!The types and interface are well-defined, providing good type safety while maintaining flexibility with the
Record
type for query parameters.
111-118
: Clean implementation of options builder!The function follows the single responsibility principle and properly handles the separation of concerns.
127-144
:✅ Verification successful
Consistent implementation across navigation methods.
The navigation functions are well-implemented. However, let's verify that all navigation method calls in the codebase have been updated to handle the new query parameter support.
🏁 Script executed:
#!/bin/bash # Search for direct calls to uni.navigateTo, uni.redirectTo, or uni.reLaunch # to ensure they're using the router wrapper instead rg "uni\.(navigateTo|redirectTo|reLaunch)\(" -A 2Length of output: 526
Navigation methods uniformly updated and verified.
The navigation functions now consistently incorporate query parameter handling via the router wrapper. Our repository search confirms that all calls to
uni.navigateTo
,uni.redirectTo
, anduni.reLaunch
are encapsulated withinsrc/useRouter/index.ts
, with no stray calls bypassing this layer.
- Verified usage in
src/useRouter/index.ts
is consistent.- No direct calls to
uni.*
functions are found elsewhere in the codebase.Approved as-is.
package.json (1)
79-80
:✅ Verification successful
Verify the fast-querystring package version.
Let's check if version 1.1.2 is the latest stable version and review its security status.
🌐 Web query:
What is the latest version of fast-querystring npm package and are there any known security vulnerabilities?
💡 Result:
The latest version of the fast-querystring npm package is 1.1.2, last published on June 5, 2023[4][7][10]. This module serves as a faster alternative to Node.js's legacy
querystring
library for parsing and stringifying URL query parameters[4].Regarding security vulnerabilities:
- No direct security advisories are documented in the provided search results for
fast-querystring
itself[4][10].- A similar-sounding package (
fast-string-search
) had a critical Denial of Service vulnerability (CVE-2022-22138) due to improper handling of non-string inputs[2], but this is unrelated tofast-querystring
.Key considerations:
- The package hasn't been updated since mid-2023[7], though this doesn't inherently indicate insecurity.
- It's used by over 11,954 projects[7], suggesting community trust.
- When handling untrusted input, validate data types before parsing to mitigate potential edge-case risks (general security practice)[5].
For verification:
- Check vulnerability databases like Snyk or GitHub Security Advisories for real-time updates[8].
- Use tools like
npm audit
to scan projects using this dependency[5].Citations:
- 1: Replacing querystring with fast-querystring expressjs/express#4990
- 2: https://www.acunetix.com/vulnerabilities/sca/cve-2022-22138-vulnerability-in-npm-package-fast-string-search/
- 3: https://www.npmjs.com/package/axios
- 4: https://npmjs.com/package/fast-querystring
- 5: https://www.aquasec.com/cloud-native-academy/supply-chain-security/npm-vulnerabilities/
- 6: https://npm-compare.com/qs,query-string,querystring,url-parse
- 7: https://deps.dev/npm/fast-querystring/1.1.1/versions
- 8: https://www.nodejs-security.com/blog/where-to-find-npm-vulnerabilities
- 9: After updating npm packages. Error: Could not parse template expression: vue-styleguidist/vue-styleguidist#1299
- 10: https://debricked.com/select/package/npm-fast-querystring
Verified: The fast-querystring dependency is up-to-date and secure.
After checking the latest npm information, version 1.1.2 is confirmed as the most recent stable release with no reported security vulnerabilities. This dependency is therefore acceptable as-is.
- File: package.json (Lines 79-80)
- Dependency: fast-querystring version ^1.1.2
close, cause of #45 (comment) . |
Description 描述
useRouter
新增query参数Summary by CodeRabbit
New Features
Documentation