Repository navigation
Refuse shadowing ids in install_unit(), and add override to redefine database ids - #452
Merged
Merged
Conversation
install_unit() only checked the map of the same kind, but udunits reads an identifier by name (whatever its case), then by symbol, then the same after stripping a prefix. So a new name "m" or symbol "km" silently redefined a database unit, and a symbol "gal" was accepted but never reached, since the database name "gal" wins over it. - Refuse an id that udunits currently reads as a different unit. - Refuse a name with a case variant that is read as a different unit (e.g. "KG" would shadow "kg"). Names with at most 12 letters try every variant; no database symbol, prefixed or not, is longer than 8 characters, so longer names are checked against installed symbols only. - After mapping, every id must be read back as the new unit (e.g. "zz1" is read as zz^1); otherwise roll back and refuse. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
remove_unit() only warned about ids it had not installed when they were in the map of their own kind, so removing "km" (read by prefix), a name "m" (a database symbol) or a symbol "gal" (a database name) did nothing silently. Decide by what udunits reads the id as instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Before #449, remove_unit() on a database id followed by install_unit() was the only way to give such an id another meaning, and it is no longer possible (#451). install_unit(..., override = TRUE) does it in one step and reversibly: - The database mappings that give an id another meaning are set aside: the id in both the symbol and name maps, and the unit's own symbol or name when it is that id. They are recorded under the installed id, and remove_unit() puts them back after undoing the install. - Setting aside, mapping and the read-back check run as one transaction, rolled back on any failure. - What each id meant before is reported with a message, by whatever route (e.g. "km" by prefix). - Ids installed by install_unit() must be removed first, and other ids a new name would shadow are still refused; case variants of the name itself (e.g. "microN" for "micron") are not. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #452 +/- ##
==========================================
+ Coverage 94.22% 94.81% +0.59%
==========================================
Files 22 22
Lines 1315 1465 +150
==========================================
+ Hits 1239 1389 +150
Misses 76 76 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A database mapping set aside by an override was filed under whichever installed id set it aside first. When an id was overridden as both a symbol and a name, removing the symbol first tried to put the database name back while the new name still held it; the failure went unnoticed, and the database name was lost once the new name was removed (#451). Any installed id, of either kind, that would set a mapping aside needs it out of the way: symbols as they are, names whatever their case. So when an id is removed, a mapping it set aside is handed to such an id if one is left, and put back only when none is. This works in any removal order, for ids installed in one call or in separate ones, and keeps the other kind's override working when only one kind is removed. - A mapping that cannot be put back is reported instead of ignored. - remove_unit() no longer warns "left unchanged" about an id that the same call put back, e.g. remove_unit("gal", "gal") after overriding only the symbol. - The override message and the docs say that overriding a symbol sets aside the name spelled the same in any letter case. Supersedes #453, whose test is included. Co-Authored-By: Robin Shannon <32329438+vorpalvorpal@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #451. Follows up on #449.
Problem 1: installs that silently redefine or never reach a unit
install_unit()only checked whether an id was already taken in the map of its own kind. But udunits reads an identifier by name (case-insensitive), then by symbol, then the same after stripping a prefix. So onmain:Fix:
KGwould makekgand every prefixed form of it read as the new unit. Names with at most 12 letters try every variant (a few ms). No database symbol, prefixed or not, is longer than 8 characters, so longer names are only checked against installed symbols.zz1is read aszz¹). Otherwise everything is rolled back.remove_unit()also decides by what udunits reads an id as, soremove_unit("km")now warns instead of silently doing nothing.Problem 2: no way to redefine a database id (#451)
Before #449,
remove_unit()followed byinstall_unit()could give a database id a new meaning. That is no longer possible. This PR addsinstall_unit(..., override = TRUE):m, meter would still print as[m]and be read back as the new unit). They are recorded under the installed id, andremove_unit()restores them after undoing the install.km, by prefix).override = TRUE: other ids that a new name would shadow (KG→kg), and ids installed byinstall_unit()("remove it first"). Case variants of the name itself (e.g.microNformicron) are not collateral.kgal). Existingunitsobjects that use the id are read with the new meaning too. Both are documented in?install_unit.Testing
src/user_units.cpporR/user_conversion.R.%, which is refused on purpose. Afterwards, every id parses to the same unit and every unit has the same own symbol and name in all three encodings (UTF-8, Latin-1 and ASCII sessions).Commits
remove_unit()about any id udunits reads as a unit.overrideargument toinstall_unit().🤖 Generated with Claude Code