Repository navigation
fix(simulator): encode station identity in WebSocket connection URL - #2177
Conversation
…ervision connection URL ChargingStation.wsConnectionUrl appended the raw chargingStationId to the supervision URL, so a reserved character in the identity became URL syntax: 'FRESH#1' turned into the fragment 'SAP#1' (ws throws 'The URL contains a fragment identifier'), 'A?B' into a query and 'A/B' into two path segments. OCPP-J 1.6 section 3.1.1 requires the identity to be percent-encoded as per RFC 3986. Encode it with encodeURIComponent when composing the connection URL only; the raw identity is unchanged everywhere else. Closes SAP#2176 Signed-off-by: VitorCoelho <vitorc195@gmail.com>
…ision connection URL
Exercise ChargingStation.wsConnectionUrl with identities holding reserved
characters (' ', '%', '/', '?', '#'), through the station info and the OCPP
configuration key paths, and against real TCP and Unix socket WebSocket
servers that must observe a single encoded path segment.
Signed-off-by: VitorCoelho <vitorc195@gmail.com>
There was a problem hiding this comment.
🔍 PR Review — Fix/encode station identity in ws url
🟡 Suggestions (1 open, 1 total)
| Category | Finding | File |
|---|---|---|
| ⚙️ Correctness | RFC 3986 reserved characters remain unencoded | charging-station/ChargingStation.ts:283 |
You're seeing this review as part of a pilot for our new /review+ experience. To help us continuously improve, check the feedback boxes on the comments below or share your thoughts in our Community channel.
PR Bot Information
Version: 1.33.24
- Experiment Variant:
treatment - LLM:
gpt-5.6-sol - Correlation ID:
dc3f77e0-d482-11f1-80d7-8098ddabf910 - Event Trigger:
issue_comment.created - Agent Instructions:
- File Content Strategy: Full file content
There was a problem hiding this comment.
Changes requested
Two confirmed issues need fixes before merge:
- The encoded connection URL no longer round-trips through the existing Web UI URL editor. Saving without changing the URL duplicates the station identity.
- The new Unix-socket test fails on Windows and breaks the simulator CI job.
Verification: 35 targeted tests passed on Linux with Node 24.22.2. The UI round-trip regression was reproduced against the base and head using the existing UI helper, real ChargingStation instances, and a local TCP WebSocket server, on both supervision-source branches. The Windows failure is directly documented in the CI job log.
The identity-encoding approach itself is appropriate; please update its existing consumer and make the transport-specific test portable.
PR title
Please rename Fix/encode station identity in ws url to follow the repository Conventional Commits requirement, for example:
fix(simulator): encode station identity in WebSocket connection URL
This is PR metadata compliance, separate from the two P2 code findings above.
…rvision URL
The connection URL published to the UI now ends with the identity encoded
as one path segment, but stripStationId only matched the raw '/<id>'
suffix. SetSupervisionUrlDialog therefore prefilled the full connection
URL as the base URL and a save without editing it (for example a
credentials-only update) stored that as the base and appended the
identity again ('/OCPP16/CS%2B1/CS%2B1').
Match the encoded suffix first and keep the raw one for URLs composed
without encoding.
Signed-off-by: VitorCoelho <vitorc195@gmail.com>
Prefill for 'CS+1', 'CS@1', 'CS 1' and 'FRESH#1', and a credentials-only save that must resend the base URL unchanged. Signed-off-by: VitorCoelho <vitorc195@gmail.com>
On Windows the socket path is not a listenable filesystem path
('listen EACCES'), which failed the simulator CI job. Only the Unix
transport case is skipped on win32; the TCP case still runs everywhere.
Signed-off-by: VitorCoelho <vitorc195@gmail.com>
jerome-benoit
left a comment
There was a problem hiding this comment.
Re-review: functional fixes verified
The two P2 findings from my previous review are fixed on 793445b1: the UI now removes the encoded identity before resubmitting the base URL, and only the Unix transport test is skipped on Windows. The current Windows simulator jobs pass. These findings no longer justify blocking the PR.
Required before merge: PR title
The title Fix/encode station identity in ws url still does not meet the repository Conventional Commits requirement. Please rename it, for example:
fix(simulator): encode station identity in WebSocket connection URL
This request for changes concerns that remaining contribution requirement, not a remaining P1/P2 code defect.
Non-blocking test cleanup
The inline P3 suggestion concerns real station resources left active after the new tests. It is not a CI regression: the official runner already uses --test-force-exit.
Verification
- Fresh source review and two independent analyses, with findings cross-validated.
- Node 24.22.2: 35 targeted simulator tests and 58 Web UI dialog tests passed.
- 44 real TCP/Unix round trips passed across both supervision-source branches, including station-data publication, the existing UI helper, credentials-only setter updates, and server-observed paths. Raw identity and hash remained unchanged.
- Current Windows CI confirms TCP runs and Unix is skipped.
The bot suggestion to additionally escape !'()* is not a demonstrated correctness issue: RFC 3986 §3.3 permits these characters within a path segment. No additional escaping is required by the consumers examined.
…ncoding tests The test file built real ChargingStation instances and never deleted them, so their BroadcastChannels stayed open and the file only finished because the CI runner forces exit. Each test now records the stations it creates and afterEach awaits station.delete(false) for each of them before the templates are removed. Without --test-force-exit the file now exits on its own. Signed-off-by: VitorCoelho <vitorc195@gmail.com>
jerome-benoit
left a comment
There was a problem hiding this comment.
Approved
The previous findings are addressed: the UI removes the encoded identity correctly, the Unix test is skipped only on Windows, real test stations are torn down, and the title follows Conventional Commits.
Verification
- Five identity tests exit naturally without forced termination.
- 289 targeted simulator tests and 58 UI dialog tests passed on the integrated code.
- 48 real TCP/Unix round trips passed across both supervision sources; raw identity and hash remain unchanged.
- Integration with
main(298b8469) preserves the OCPP and storage fixes.
No remaining actionable finding. Pre-existing endpoint coverage and UI normalization gaps remain tracked separately in #2172 and #2173.
PR Checklist
Does this PR introduce a breaking change?
If yes please indicate it in the title and add migration info into the documentation.
Closes #2176
Summary
ChargingStation.wsConnectionUrlappended the rawchargingStationIdto the supervision URL. A reserved character in the identity therefore became URL syntax instead of part of the identity:FRESH#1.../OCPP16/FRESH+ fragment#1→wsthrowsThe URL contains a fragment identifier.../OCPP16/FRESH%231CS?1.../OCPP16/CS+ query?1.../OCPP16/CS%3F1CS/1CSand1.../OCPP16/CS%2F1CS 1CS%201by luck.../OCPP16/CS%201(now intentional)CS%1.../OCPP16/CS%1(malformed escape).../OCPP16/CS%251CS-1.../OCPP16/CS-1OCPP-J 1.6 section 3.1.1 requires the identity path segment to be percent-encoded as per RFC 3986. The identity is now passed through
encodeURIComponentonly when the connection URL is composed; the raw identity is unchanged everywhere else (station info, templates, logs, configuration keys, UI). Both the supervision URL from the station info and the one taken from the OCPP configuration key (supervisionUrlOcppConfiguration) go through the same getter, so both paths are covered.Testing
New
tests/charging-station/ChargingStation-WsConnectionUrlIdentity.test.ts:CS-1) produces the same URL as before;pathnameends with the encoded identity,searchandhashare empty, anddecodeURIComponentof the last segment gives back the raw identity;supervisionUrlOcppConfiguration: true, keyocppcentraladdress) is encoded the same way;wsWebSocketServeron TCP and on a Unix socket (ws+unix:), the server receives/OCPP16/<encoded identity>as the request path, i.e. the identity survives the round trip as one segment.Without the fix, 4 of the 5 tests fail (the fragment case throws inside
ws, the others land on a different path). With it, 5/5 pass;pnpm lint,pnpm typecheckand the neighbouringtests/charging-station/*.test.tssuites are clean.