Opened 12 years ago

Closed 12 years ago

#4843 closed Bugs (fixed)

GraphML parser broken

Reported by: Alexandre Romana <alexandre.romana@…> Owned by: Andrew Sutton
Milestone: To Be Determined Component: graph
Version: Boost 1.44.0 Severity: Problem
Keywords: GraphML Cc:

Description

Hi,

First of all, thanks for the library, it's awesome. However, latest versions are not able to correctly parse graphML files. The GraphML standard states the following for the edge attributes:

  • id (optional)
  • directed (optional)
  • source (required)
  • target (required)
  • sourceport (optional)
  • targetport (optional)

In trunk/libs/graph/src/graphml.cpp@63244:

We have:

90            BOOST_FOREACH(const ptree* gr, graphs) {
91              bool default_directed = gr->get<std::string>(path("<xmlattr>/edgedefault")) == "directed";
92              // Search for edges
93              BOOST_FOREACH(const ptree::value_type& edge, *gr) {
94                if (edge.first != "edge") continue;
95                std::string id = edge.second.get<std::string>(path("<xmlattr>/id"));
96                std::string source = edge.second.get<std::string>(path("<xmlattr>/source"));
97                std::string target = edge.second.get<std::string>(path("<xmlattr>/target"));
98                std::string local_directed = edge.second.get(path("<xmlattr>/directed"), "");
99                bool is_directed = (local_directed == "" ? default_directed : local_directed == "true");
100               if (is_directed != m_g.is_directed()) {
101                 if (is_directed) {
102                   BOOST_THROW_EXCEPTION(directed_graph_error());
103                 } else {
104                   BOOST_THROW_EXCEPTION(undirected_graph_error());
105                 }
106               }

Should be (look at line 95):

90            BOOST_FOREACH(const ptree* gr, graphs) {
91              bool default_directed = gr->get<std::string>(path("<xmlattr>/edgedefault")) == "directed";
92              // Search for edges
93              BOOST_FOREACH(const ptree::value_type& edge, *gr) {
94                if (edge.first != "edge") continue;
95                std::string id = edge.second.get<std::string>(path("<xmlattr>/id"), "");
96                std::string source = edge.second.get<std::string>(path("<xmlattr>/source"));
97                std::string target = edge.second.get<std::string>(path("<xmlattr>/target"));
98                std::string local_directed = edge.second.get(path("<xmlattr>/directed"), "");
99                bool is_directed = (local_directed == "" ? default_directed : local_directed == "true");
100               if (is_directed != m_g.is_directed()) {
101                 if (is_directed) {
102                   BOOST_THROW_EXCEPTION(directed_graph_error());
103                 } else {
104                   BOOST_THROW_EXCEPTION(undirected_graph_error());
105                 }
106               }

Change History (1)

comment:1 by Jeremiah Willcock, 12 years ago

Resolution: fixed
Status: newclosed

(In [66528]) Removed access to (unused) edge id attribute, also making that attribute optional; fixes #4843

Note: See TracTickets for help on using tickets.