Skip to content
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: Accept URL escape for device command name and resource name #4376

Merged
merged 1 commit into from
Feb 24, 2023

Conversation

weichou1229
Copy link
Member

@weichou1229 weichou1229 commented Feb 21, 2023

  • Use router.UseEncodedPath() to match the encoded original path to the routes
  • Decode the Url path variable before passing to the controller

Close #4371

If your build fails due to your commit message not passing the build checks, please review the guidelines here: https://github.com/edgexfoundry/edgex-go/blob/main/.github/Contributing.md

PR Checklist

Please check if your PR fulfills the following requirements:

  • I am not introducing a breaking change (if you are, flag in conventional commit message with BREAKING CHANGE: describing the break)
  • I am not introducing a new dependency (add notes below if you are)
  • I have added unit tests for the new feature or bug fix (if not, why?)
  • I have fully tested (add details below) this the new feature or bug fix (if not, why?)
  • I have opened a PR for the related docs change (if not, why?) not impact

Testing Instructions

  • Run core service and device service based on the core-contract and device-sdk changes.
  • Add a profile to the metadata service, the command name and resource name should contain special character like :
  • Add a device to the metadata service
  • Test the read command or write command
    • Verify the escape URL works, eg, escape the commandName device-a/test:value and put into the URL like /api/v2/device/name/Modbus-TCP-Device/device-a%2Ftest%3Avalue

New Dependency Instructions (If applicable)

@weichou1229 weichou1229 marked this pull request as ready for review February 22, 2023 06:05
@weichou1229 weichou1229 marked this pull request as draft February 22, 2023 06:19
@codecov-commenter
Copy link

codecov-commenter commented Feb 22, 2023

Codecov Report

Merging #4376 (6ccadbc) into main (76c26b6) will decrease coverage by 0.03%.
The diff coverage is 36.36%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main    #4376      +/-   ##
==========================================
- Coverage   43.71%   43.68%   -0.03%     
==========================================
  Files         116      116              
  Lines       10713    10719       +6     
==========================================
  Hits         4683     4683              
- Misses       5610     5614       +4     
- Partials      420      422       +2     
Impacted Files Coverage Δ
internal/core/data/application/event.go 62.59% <0.00%> (ø)
...rnal/core/command/controller/messaging/internal.go 49.25% <25.00%> (-1.13%) ⬇️
...rnal/core/command/controller/messaging/external.go 85.29% <40.00%> (-2.59%) ⬇️
...nternal/core/command/controller/messaging/utils.go 66.03% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@weichou1229 weichou1229 force-pushed the issue-4371 branch 2 times, most recently from 3f9a769 to 6ccadbc Compare February 22, 2023 08:29
@weichou1229 weichou1229 marked this pull request as ready for review February 23, 2023 02:54
commandName := topicLevels[length-2]
commandName, err := url.QueryUnescape(topicLevels[length-2])
if err != nil {
lc.Errorf("Failed to unescape command name '%s'", commandName)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lc.Errorf("Failed to unescape command name '%s'", commandName)
lc.Errorf("Failed to unescape command name '%s'", commandName)
lc.Warn("Not publishing error message back due to insufficient information on response topic")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the log.

internal/core/command/controller/messaging/internal.go Outdated Show resolved Hide resolved
- Use router.UseEncodedPath() to match the encoded original path to the routes
- Decode the Url path variable before passing to the controller

Close edgexfoundry#4371

Signed-off-by: bruce <weichou1229@gmail.com>
@sonarcloud
Copy link

sonarcloud bot commented Feb 24, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@lenny-goodell lenny-goodell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

Accept URL escape for device command name and resource name
3 participants