Skip to content

Commit 6404afd

Browse files
chapulinascpetersaaronchongth
authored
Fix parsing 'type' attibutes in plugins (#809)
Signed-off-by: Louise Poubel <louise@openrobotics.org> * Add line with unrecognized type Signed-off-by: Steve Peters <scpeters@openrobotics.org> * Fix for custom element with attribute 'type' (#811) * Reverted changes to parser for custom element with attribute 'type', added fix in ParamPrivate::ValueFromStringImpl instead Signed-off-by: Aaron Chong <aaronchongth@gmail.com> Co-authored-by: Steve Peters <scpeters@openrobotics.org> Co-authored-by: Aaron Chong <aaronchongth@gmail.com>
1 parent 8785b7a commit 6404afd

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

src/Param.cc

+10-7
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,17 @@ bool ParamPrivate::ValueFromStringImpl(const std::string &_typeName,
640640
std::string tmp(trimmed);
641641
std::string lowerTmp = lowercase(trimmed);
642642

643-
// "true" and "false" doesn't work properly
644-
if (lowerTmp == "true")
643+
// "true" and "false" doesn't work properly (except for string)
644+
if (_typeName != "string" && _typeName != "std::string")
645645
{
646-
tmp = "1";
647-
}
648-
else if (lowerTmp == "false")
649-
{
650-
tmp = "0";
646+
if (lowerTmp == "true")
647+
{
648+
tmp = "1";
649+
}
650+
else if (lowerTmp == "false")
651+
{
652+
tmp = "0";
653+
}
651654
}
652655

653656
bool isHex = lowerTmp.compare(0, 2, "0x") == 0;

src/Plugin_TEST.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ TEST(DOMPlugin, LoadWithChildren)
186186
std::string pluginStr = R"(<plugin name='3D View' filename='MinimalScene'>
187187
<ignition-gui>
188188
<title>3D View</title>
189-
<property type='bool' key='showTitleBar'>false</property>
189+
<property type='Ignition.Msgs.Boolean'>false</property>
190+
<property type='bool' key='showTitleBar'>0</property>
190191
<property type='string' key='state'>docked</property>
191192
</ignition-gui>
192193
<engine>ogre</engine>

src/parser.cc

+8-16
Original file line numberDiff line numberDiff line change
@@ -1912,13 +1912,13 @@ void copyChildren(ElementPtr _sdf,
19121912
for (elemXml = _xml->FirstChildElement(); elemXml;
19131913
elemXml = elemXml->NextSiblingElement())
19141914
{
1915-
std::string elem_name = elemXml->Name();
1915+
std::string elemName = elemXml->Name();
19161916

1917-
if (_sdf->HasElementDescription(elem_name))
1917+
if (_sdf->HasElementDescription(elemName))
19181918
{
19191919
if (!_onlyUnknown)
19201920
{
1921-
sdf::ElementPtr element = _sdf->AddElement(elem_name);
1921+
sdf::ElementPtr element = _sdf->AddElement(elemName);
19221922

19231923
// FIXME: copy attributes
19241924
for (const auto *attribute = elemXml->FirstAttribute();
@@ -1941,26 +1941,18 @@ void copyChildren(ElementPtr _sdf,
19411941
{
19421942
ElementPtr element(new Element);
19431943
element->SetParent(_sdf);
1944-
element->SetName(elem_name);
1945-
std::optional<std::string> typeName = std::nullopt;
1944+
element->SetName(elemName);
19461945
for (const tinyxml2::XMLAttribute *attribute = elemXml->FirstAttribute();
19471946
attribute; attribute = attribute->Next())
19481947
{
1949-
const std::string attributeName(attribute->Name());
1950-
if (attributeName == "type")
1951-
typeName = attribute->Value();
1952-
1953-
element->AddAttribute(attributeName, "string", "", 1, "");
1954-
element->GetAttribute(attributeName)->SetFromString(
1955-
attribute->Value());
1948+
element->AddAttribute(attribute->Name(), "string", "", 1, "");
1949+
element->GetAttribute(attribute->Name())->SetFromString(
1950+
attribute->Value());
19561951
}
19571952

19581953
if (elemXml->GetText() != nullptr)
19591954
{
1960-
if (typeName.has_value())
1961-
element->AddValue(typeName.value(), elemXml->GetText(), true);
1962-
else
1963-
element->AddValue("string", elemXml->GetText(), true);
1955+
element->AddValue("string", elemXml->GetText(), true);
19641956
}
19651957

19661958
copyChildren(element, elemXml, _onlyUnknown);

0 commit comments

Comments
 (0)