Skip to content

Fix case-insensitive input handling for all string setters in accessors#168

Merged
jgphilpott merged 3 commits intomainfrom
copilot/fix-support-generation-issue
Mar 2, 2026
Merged

Fix case-insensitive input handling for all string setters in accessors#168
jgphilpott merged 3 commits intomainfrom
copilot/fix-support-generation-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 1, 2026

Several string setters in src/utils/accessors.coffee silently ignored valid input when the casing didn't exactly match the canonical stored value. The most impactful instance was setSupportPlacement('buildPlate') failing after a prior setSupportPlacement('everywhere') call, causing the sideways dome with buildPlate placement to generate 95 spurious support lines instead of 0.

Root Cause

toLowerCase() converts camelCase input to all-lowercase, which then fails to match camelCase entries in validation arrays:

# Before — "buildplate" never matches "buildPlate" in the array
placement = placement.toLowerCase().trim()
if ["everywhere", "buildPlate"].includes placement
    slicer.supportPlacement = String placement

The same pattern affected setSpeedUnit (which had no toLowerCase() at all, requiring exact-match for camelCase values like "millimeterSecond"), and setPositioningMode / setExtruderMode (which had no toLowerCase(), so "Relative" or "ABSOLUTE" silently failed).

Fix

Normalize input to lowercase for comparison, then store the canonical form:

normalized = placement.toLowerCase().trim()
if normalized is "buildplate"
    slicer.supportPlacement = "buildPlate"
else if normalized is "everywhere"
    slicer.supportPlacement = "everywhere"

The same approach is applied to setSpeedUnit. For setPositioningMode and setExtruderMode, a toLowerCase() call is added before the existing array check (no canonical remapping needed since values are already lowercase).

Changes

  • src/utils/accessors.coffee — fixed four setters:
    • setSupportPlacement: normalize + compare lowercase + store canonical camelCase
    • setSpeedUnit: added toLowerCase() normalization; maps to canonical "millimeterSecond", "inchSecond", "meterSecond"
    • setPositioningMode: added toLowerCase() before comparison
    • setExtruderMode: added toLowerCase() before comparison
  • src/slicer/support/support.test.coffee — regression test: set to 'everywhere', then back to 'buildPlate', assert value is 'buildPlate'
  • src/utils/accessors.test.coffee — added:
    • should set and get speed unit — covers all three speed unit values and case variants
    • Case-insensitive assertions in existing setPositioningMode and setExtruderMode tests
    • should accept case-insensitive input for all string setters — catch-all test covering all 14 string setters with uppercase input to prevent future regressions
  • resources/gcode/support/normal/dome/sideways-buildPlate.gcode — regenerated; support line count drops from 95 → 0

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix support generation issue in sideways dome example Fix setSupportPlacement silently ignoring 'buildPlate' after 'everywhere' Mar 1, 2026
@jgphilpott
Copy link
Owner

Great catch @copilot, here are some more things to do:

  • Double check src/polyslice.coffee and src/utils/accessors.coffee to be sure this bug isn't affecting any other settings that may have capital letters in their name as well, then update methods and tests accordingly (a catch all test would be nice to ensure this doesn't happen again in the future with a new setting).
  • Also, please ensure that we have full test coverage of all the settings and methods in src/polyslice.coffee and src/utils/accessors.coffee, I feel like coverage might have fallen short at some point.

All setters should be able to take input in capitalized or non-capitalized form but save the value in capitalized form so that the getter returns the proper format.

…xtruderMode; add catch-all test

Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 2, 2026

Great catch @copilot, here are some more things to do:

  • Double check src/polyslice.coffee and src/utils/accessors.coffee to be sure this bug isn't affecting any other setting...

Done in commit 63b52ed.

Additional setters fixed (same toLowerCase() vs camelCase mismatch pattern):

  • setSpeedUnit — had no toLowerCase() at all; "millimeterSecond", "inchSecond", "meterSecond" only matched on exact input
  • setPositioningMode — no toLowerCase(), so "Relative" / "ABSOLUTE" silently failed
  • setExtruderMode — same issue as above

New tests added:

  • should set and get speed unit — covers all three values and case variants
  • Case-insensitive assertions added to existing setPositioningMode and setExtruderMode tests
  • should accept case-insensitive input for all string setters — catch-all that passes uppercase input to every string setter (setWorkspacePlane, setTimeUnit, setLengthUnit, setSpeedUnit, setTemperatureUnit, setAngleUnit, setInfillPattern, setInfillPatternCentering, setSupportType, setSupportPlacement, setAdhesionType, setSkirtType, setPositioningMode, setExtruderMode) and asserts each returns the canonical stored form.

Copilot AI changed the title Fix setSupportPlacement silently ignoring 'buildPlate' after 'everywhere' Fix case-insensitive input handling for all string setters in accessors Mar 2, 2026
@jgphilpott jgphilpott marked this pull request as ready for review March 2, 2026 08:20
Copilot AI review requested due to automatic review settings March 2, 2026 08:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes case-insensitive handling in Polyslice’s string-based configuration setters so valid inputs aren’t silently rejected due to casing/camelCase mismatches (notably restoring correct supportPlacement switching behavior that affected support generation outcomes).

Changes:

  • Normalize inputs in key string setters (speed unit, support placement, positioning mode, extruder mode) while storing canonical values.
  • Add/extend regression tests to ensure case-insensitive setter behavior (including a broad “all string setters” guard test).
  • Regenerate affected support G-code fixture outputs (LFS pointers updated) to reflect corrected configuration handling.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/utils/accessors.coffee Implements case-insensitive normalization and canonical storage for affected string setters.
src/utils/accessors.test.coffee Adds targeted + catch-all tests ensuring string setters accept case-insensitive inputs and store canonical values.
src/slicer/support/support.test.coffee Adds regression test for switching supportPlacement from everywhere back to buildPlate.
resources/gcode/support/tree/dome/sideways-buildPlate.gcode Updates LFS pointer for regenerated fixture output after config-handling fix.
resources/gcode/support/tree/arch/sideways-buildPlate.gcode Updates LFS pointer for regenerated fixture output after config-handling fix.
resources/gcode/support/threshold/80-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/70-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/60-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/50-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/40-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/30-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/20-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/10-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/threshold/0-degrees.gcode Updates LFS pointer for regenerated threshold fixture output.
resources/gcode/support/normal/dome/sideways-buildPlate.gcode Updates LFS pointer for regenerated fixture output reflecting corrected buildPlate placement behavior.
resources/gcode/support/normal/dome/flipped.gcode Updates LFS pointer for regenerated fixture output.

@jgphilpott jgphilpott merged commit 3027ac3 into main Mar 2, 2026
5 checks passed
@jgphilpott jgphilpott deleted the copilot/fix-support-generation-issue branch March 2, 2026 08:35
Copilot AI mentioned this pull request Mar 8, 2026
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.

3 participants