Skip to content

Fix crash when splitting a loop way in a route with node members - #13185

Closed
rajanpanth wants to merge 3 commits into
openstreetmap:developfrom
rajanpanth:fix/split-loop-route-non-way-members
Closed

rajanpanth wants to merge 3 commits into
openstreetmap:developfrom
rajanpanth:fix/split-loop-route-non-way-members

Conversation

@rajanpanth

Copy link
Copy Markdown

Splitting a closed way that a route relation enters and leaves at the same node (a "spoon" loop, e.g. a bus turning loop) throws when the member two places before or after it is not a way:

TypeError: Cannot read properties of undefined (reading 'length')

That is the usual shape of a public transport route, where stop and platform nodes are listed before the ways. With the spoon1 fixture from test/spec/actions/split.js and the members ['s', 'p', '~', '-', '~'] (s and p are nodes), actionSplit('d', ['=']) throws. disabled() doesn't block the split, so the operation is offered and then fails.

Cause

In splitWayMember, the "loops" branch looks one member further (members[i - 2] / members[i + 2]) and passes it to connects(), which reads .nodes. The direct neighbours a few lines above are only compared when type === 'way'; this branch had no such check.

The same branch used i > 2 for the look-behind, so members[0] was never looked at when the split way is the third member. In that case the two halves could be inserted in the wrong order: for ['-', '~', '#', '~'] where ~ and # both run from a to b, splitting # gave ['-', '~', '#', '=', '~'] with # = [a, y], which doesn't touch b where the preceding ~ ends. With one more member in front, the same data was ordered correctly.

Changes

  • Only compare members[i ± 2] when it is a way, like the direct neighbours.
  • Look behind when i >= 2.

Tests

Three cases added to the "splitting spoon routes" block: a stop node after the ways, stop and platform nodes before the ways, and the third-member case. All three fail on develop (two with the TypeError, one with the wrong order) and pass with this change.

npm run test:once (2305 tests) and tsc pass locally. eslint is clean for the two changed files apart from linebreak-style, which is my Windows checkout.

AI disclosure: this bug was found, and the fix and tests written, with Claude Code. The reproduction and the test results above come from running them locally against develop.

🤖 Generated with Claude Code

rajanpanth and others added 3 commits November 10, 2026 12:23
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…te-non-way-members

# Conflicts:
#	CHANGELOG.md
@matkoniecz

Copy link
Copy Markdown
Collaborator

close per https://agentscan.tools/user/rajanpanth - classified as large volume account, looks like it submits LLM generated PRs without human review

@matkoniecz matkoniecz closed this Nov 10, 2026
@matkoniecz

Copy link
Copy Markdown
Collaborator

if it is a real bug: please attach before and after reproduction (screen capture, preferably in form of video) that demonstrates that bug is real and not just LLM hallucination

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.

2 participants