Fix missing default class name when attaching a spec without prefix or suffix#3333
Open
discobot wants to merge 1 commit into
Open
Fix missing default class name when attaching a spec without prefix or suffix#3333discobot wants to merge 1 commit into
discobot wants to merge 1 commit into
Conversation
Open
2 tasks
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
…r suffix When a spec is attached with an empty prefix and suffix, the copy of the child's global default keeps the name 'main', silently overwrites the parent's entry in def_map and is serialized as a nameless <default/> element that cannot be parsed back. Make the name of an attached default tree unique before inserting it into the model, matching the behavior already produced by non-empty prefixes. Add a regression test attaching a spec without prefix or suffix and verifying that the saved XML round-trips. Fixes google-deepmind#2707.
1123939 to
f1d3512
Compare
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.
Fixes #2707.
The attach paths copy the child's root default tree and only apply
mjCDef::NameSpace, which prepends the prefix/suffix to each name. With anempty prefix and suffix the copy keeps the reserved name
main, andmjCModel::operator+=(mjCDef&)inserted it without a collision check, silentlyoverwriting
def_map["main"]. Since the XML writer omits theclassattributefor any default named
mainand resolves every element's class throughdef_map, this both emits the nameless nested<default/>and corrupts how theparent's own elements are serialized.
This change renames the incoming default tree's root to a unique name
(
main_1, ...) inmjCModel::operator+=(mjCDef&)before insertion, mirroringthe disambiguation that non-empty prefixes already provide. It also covers the
more general collision — e.g. parent and child both defining a class with the
same name, or attaching the same spec twice with identical prefixes — which
previously serialized as duplicate class names that fail to reload with
"repeated default class name".
Added a regression test that attaches a child spec with defaults using empty
prefix/suffix and checks that the parent's global default is not clobbered, the
saved XML loads back, and the reloaded model is identical. Before the fix it
fails with
XML Error: empty class name; with the fix the user and XML testsuites pass.