Skip to content

@@W-19811971@@ - Fix address name encoding for server double-decoding issue - #3380

Merged
bendvc merged 3 commits into
developfrom
bendvc/W-19811971_encode-address-name
Oct 8, 2025
Merged

@@W-19811971@@ - Fix address name encoding for server double-decoding issue#3380
bendvc merged 3 commits into
developfrom
bendvc/W-19811971_encode-address-name

Conversation

@bendvc

@bendvc bendvc commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

Fix address name encoding for server double-decoding issue

Problem

The server (SCAPI) performs double URL decoding on address names (potentially others), causing special characters (like %, ,) to be incorrectly decoded when passed as URL parameters in address mutations, causing a 500 error.

Solution

  • Added serverSafeEncode() utility function in utils/url.js that applies URL encoding to work around the server's double-decoding behavior
  • Updated addresses.jsx to use serverSafeEncode() for addressName parameters in both update and remove address mutations
  • Added comprehensive tests covering various character types and edge cases

Changes

  • New utility: serverSafeEncode() function with JSDoc documentation
  • Updated: Address mutations now encode addressName before sending to server
  • Added: 7 test cases for the new utility function

Future Maintenance

The utility is centralized in one place, making it easy to revert if the server-side double-decoding issue is fixed in the future by simply changing the function implementation.

How to test drive this:

  1. Open the SFRA demo site.
  2. Login and add a new address in account pages. Use Home%% as the address name.
  3. Not goto the PWA-Kit demo site and edit the address you just created in SFRA.
  4. Save the address.

This should work without issue. If you test this on production demo site you'll see a 500 error on save of the pwa kit address.

bendvc added 2 commits October 7, 2025 13:23
## Fix address name encoding for server double-decoding issue

### Problem
The server performs double URL decoding on address names, causing special characters (like `&`, `#`, spaces) to be incorrectly decoded when passed as URL parameters in address mutations.

### Solution
- Added `serverSafeEncode()` utility function in `utils/url.js` that applies URL encoding to work around the server's double-decoding behavior
- Updated `addresses.jsx` to use `serverSafeEncode()` for `addressName` parameters in both update and remove address mutations
- Added comprehensive tests covering various character types and edge cases

### Changes
- **New utility**: `serverSafeEncode()` function with JSDoc documentation
- **Updated**: Address mutations now encode `addressName` before sending to server
- **Added**: 7 test cases for the new utility function

### Future Maintenance
The utility is centralized in one place, making it easy to revert if the server-side double-decoding issue is fixed in the future by simply changing the function implementation.
@bendvc
bendvc requested a review from a team as a code owner October 7, 2025 20:27
@cc-prodsec

cc-prodsec commented Oct 7, 2025

Copy link
Copy Markdown
Collaborator

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

})
})

describe('serverSafeEncode', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Only other thing I can think of is the gross double-encoding scenario, so that would be a test case like

    test('correctly double encodes', () => {
        const input = 'My%20Address%20%26%20Co.'
        const encoded = serverSafeEncode(input)

        // Decode should give us original string
        const decoded = decodeURIComponent(encoded)
        expect(decoded).toBe(input)
    })

bfeister
bfeister previously approved these changes Oct 7, 2025

@bfeister bfeister left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small edge case for coverage if you like, but looks good 👍

@bendvc
bendvc merged commit 83c0bb7 into develop Oct 8, 2025
42 checks passed
@bendvc
bendvc deleted the bendvc/W-19811971_encode-address-name branch October 8, 2025 15:51
// Decode should give us original string
const decoded = decodeURIComponent(encoded)
expect(decoded).toBe(input)
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could you add test case for "abc%"?

test('correctly double encodes', () => {
    const input = 'abc%'
    const encoded = serverSafeEncode(input)

    // Decode should give us original string
    const decoded = decodeURIComponent(encoded)
    expect(decoded).toBe(input)
}

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.

5 participants