Autopilot: tolerate whitespace in XML strings
Prevent errors from property code when leading / trailing whitespace occurs in the autopilot XML, in a property path. Use strutils::strip to remove whitespace. Ticket-Id: https://sourceforge.net/p/flightgear/codetickets/2445/
This commit is contained in:
parent
988e377ec9
commit
b2622458cc
4 changed files with 32 additions and 18 deletions
|
@ -23,6 +23,8 @@
|
|||
#include "analogcomponent.hxx"
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
using namespace FGXMLAutopilot;
|
||||
|
||||
AnalogComponent::AnalogComponent() :
|
||||
|
@ -65,23 +67,23 @@ bool AnalogComponent::configure( SGPropertyNode& cfg_node,
|
|||
bool found = false;
|
||||
for( int i = 0; i < cfg_node.nChildren(); ++i )
|
||||
{
|
||||
SGPropertyNode& child = *cfg_node.getChild(i);
|
||||
const std::string& name = child.getNameString();
|
||||
SGPropertyNode* child = cfg_node.getChild(i);
|
||||
const std::string& name = child->getNameString();
|
||||
|
||||
// Allow "prop" for backwards compatiblity
|
||||
if( name != "property" && name != "prop" )
|
||||
continue;
|
||||
|
||||
_output_list.push_back( prop_root.getNode(child.getStringValue(), true) );
|
||||
const auto trimmed = simgear::strutils::strip(child->getStringValue());
|
||||
_output_list.push_back( prop_root.getNode(trimmed, true) );
|
||||
found = true;
|
||||
}
|
||||
|
||||
// no <prop> elements, text node of <output> is property name
|
||||
if( !found )
|
||||
_output_list.push_back
|
||||
(
|
||||
prop_root.getNode(cfg_node.getStringValue(), true)
|
||||
);
|
||||
if( !found ) {
|
||||
const auto trimmed = simgear::strutils::strip(cfg_node.getStringValue());
|
||||
_output_list.push_back(prop_root.getNode(trimmed, true));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "digitalcomponent.hxx"
|
||||
#include <Main/fg_props.hxx>
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
using std::string;
|
||||
using namespace FGXMLAutopilot;
|
||||
|
||||
|
@ -91,12 +93,16 @@ bool DigitalComponent::configure( SGPropertyNode& cfg_node,
|
|||
if( (n = cfg_node.getNode("inverted")) != NULL )
|
||||
o->setInverted( n->getBoolValue() );
|
||||
|
||||
if( (n = cfg_node.getNode("property")) != NULL )
|
||||
o->setProperty( prop_root.getNode(n->getStringValue(), true) );
|
||||
|
||||
if( cfg_node.nChildren() == 0 )
|
||||
o->setProperty( prop_root.getNode(cfg_node.getStringValue(), true) );
|
||||
|
||||
if( (n = cfg_node.getNode("property")) != NULL ) {
|
||||
const auto trimmed = simgear::strutils::strip(n->getStringValue());
|
||||
o->setProperty( prop_root.getNode(trimmed, true) );
|
||||
}
|
||||
|
||||
if( cfg_node.nChildren() == 0 ) {
|
||||
const auto trimmed = simgear::strutils::strip(cfg_node.getStringValue());
|
||||
o->setProperty( prop_root.getNode(trimmed, true) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
#include "digitalfilter.hxx"
|
||||
#include <deque>
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
namespace FGXMLAutopilot
|
||||
{
|
||||
|
||||
|
@ -472,7 +474,7 @@ bool ExponentialFilterImplementation::configure( SGPropertyNode& cfg_node,
|
|||
}
|
||||
|
||||
if (cfg_name == "type" ) {
|
||||
std::string type(cfg_node.getStringValue());
|
||||
std::string type = simgear::strutils::strip(cfg_node.getStringValue());
|
||||
_isSecondOrder = type == "double-exponential";
|
||||
}
|
||||
|
||||
|
@ -746,7 +748,7 @@ bool DigitalFilter::configure( SGPropertyNode& prop_root,
|
|||
componentForge["damped-oscillation" ] = digitalFilterFactory<DampedOscillationFilterImplementation>;
|
||||
}
|
||||
|
||||
const std::string type = cfg.getStringValue("type");
|
||||
const auto type = simgear::strutils::strip(cfg.getStringValue("type"));
|
||||
DigitalFilterMap::iterator component_factory = componentForge.find(type);
|
||||
if( component_factory == componentForge.end() )
|
||||
{
|
||||
|
@ -785,7 +787,7 @@ bool DigitalFilter::configure( SGPropertyNode& cfg_node,
|
|||
{
|
||||
if( cfg_name == "initialize-to" )
|
||||
{
|
||||
std::string s( cfg_node.getStringValue() );
|
||||
const auto s = simgear::strutils::strip(cfg_node.getStringValue());
|
||||
if( s == "input" )
|
||||
_initializeTo = INITIALIZE_INPUT;
|
||||
else if( s == "output" )
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#include "inputvalue.hxx"
|
||||
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
|
||||
using namespace FGXMLAutopilot;
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -131,7 +133,9 @@ void InputValue::parse( SGPropertyNode& prop_root,
|
|||
if( (n = cfg.getChild("property"))
|
||||
|| (n = cfg.getChild("prop" )) )
|
||||
{
|
||||
_property = prop_root.getNode(n->getStringValue(), true);
|
||||
// tolerate leading & trailing whitespace from XML, in the property name
|
||||
const auto trimmed = simgear::strutils::strip(n->getStringValue());
|
||||
_property = prop_root.getNode(trimmed, true);
|
||||
if( valueNode )
|
||||
{
|
||||
// initialize property with given value
|
||||
|
|
Loading…
Add table
Reference in a new issue