<commit_before>#include <cassert>

#include <sequanto/tree.h>
#include <sequanto/protocol.h>
#include <stdexcept>

using namespace std;
using namespace sequanto::automation;

Tree::Tree ()
   : m_root(NULL)
{
}

Node * Tree::FindNode ( const char * _path )
{
   assert ( m_root != NULL );

   string path ( _path );
   if ( path == "/" )
   {
      return m_root;
   }
   // Skip the first slash
   size_t start = 1;
   size_t end = path.find ( '/', start );
   Node * node = m_root;
   while ( end != string::npos )
   {
      node = node->FindChild ( path.substr(start, end - start) );
      if ( node == NULL )
      {
         return NULL;
      }
      start = end + 1;
      end = path.find ( '/', start );
   }
   node = node->FindChild ( path.substr ( start, path.size() - 1 ) );
   return node;
}

SQBool Tree::HandleInfo(SQStream * _stream, const char * _path)
{
   Node * node = FindNode ( _path );
   if ( node == NULL )<commit_msg>Protect againts badly formatted paths in Tree::FindNode.<commit_after>#include <cassert>

#include <sequanto/tree.h>
#include <sequanto/protocol.h>
#include <stdexcept>

using namespace std;
using namespace sequanto::automation;

Tree::Tree ()
   : m_root(NULL)
{
}

Node * Tree::FindNode ( const char * _path )
{
   assert ( m_root != NULL );

   string path ( _path );
   if ( path.empty() || path[0] != '/' )
   {
      return NULL;
   }
   if ( path == "/" )
   {
      return m_root;
   }
   // Skip the first slash
   size_t start = 1;
   size_t end = path.find ( '/', start );
   Node * node = m_root;
   while ( end != string::npos )
   {
      node = node->FindChild ( path.substr(start, end - start) );
      if ( node == NULL )
      {
         return NULL;
      }
      start = end + 1;
      end = path.find ( '/', start );
   }
   node = node->FindChild ( path.substr ( start, path.size() - 1 ) );
   return node;
}

SQBool Tree::HandleInfo(SQStream * _stream, const char * _path)
{
   Node * node = FindNode ( _path );
   if ( node == NULL )
{'fraction_non_alphanumeric': 0.1539230384807596, 'fraction_numerical': 0.0034982508745627187, 'mean_word_length': 2.4105621805792166, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7185612', 'n_tokens_mistral': 707, 'n_tokens_neox': 691, 'n_words': 181}