Changeset 11:8865b9eb5efe in rrlib_uri


Ignore:
Timestamp:
15.11.2019 09:18:20 (3 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Phase:
public
Message:

Fixes bug in URI parsing (with paths containing encoded slashes)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tPath.h

    r9 r11  
    103103    Set(path_string, separator); 
    104104  } 
    105   tPath(const std::string& path_string, char separator = '/') : tPath(tStringRange(path_string)) {} 
    106   tPath(const char* path_string, char separator = '/') : tPath(tStringRange(path_string)) {} 
     105  tPath(const std::string& path_string, char separator = '/') : tPath(tStringRange(path_string), separator) {} 
     106  tPath(const char* path_string, char separator = '/') : tPath(tStringRange(path_string), separator) {} 
    107107 
    108108  /*! 
  • tURI.cpp

    r0 r11  
    156156    throw std::invalid_argument("Cannot parse URI " + uri); 
    157157  } 
     158 
     159  // Replaces all slashes in source string with zeros - to not mix them up with decoded slashes 
     160  char encoded_path_buffer[match[5].length() + 1]; 
     161  { 
     162    const char* source_pointer = &*match[5].first; 
     163    for (long int i = 0; i < match[5].length(); i++, source_pointer++) 
     164    { 
     165      encoded_path_buffer[i] = (*source_pointer) == '/' ? 0 : (*source_pointer); 
     166    } 
     167    encoded_path_buffer[match[5].length()] = 0; 
     168  } 
     169 
    158170  char decoded_buffer[match[5].length() + 1]; 
    159   char* post_decoded = Decode(decoded_buffer, tStringRange(&*match[5].first, match[5].second - match[5].first)); 
     171  char* post_decoded = Decode(decoded_buffer, tStringRange(encoded_path_buffer, match[5].length())); 
    160172  (*post_decoded) = 0; 
    161173  result.scheme = (match.size() > 2 && match[2].matched) ? match[2] : empty; 
    162174  result.authority = (match.size() > 4 && match[4].matched) ? match[4] : empty; 
    163   result.path = (match.size() > 5 && match[5].matched) ? tPath(decoded_buffer) : tPath(); 
     175  result.path = (match.size() > 5 && match[5].matched) ? tPath(tStringRange(decoded_buffer, post_decoded - decoded_buffer), 0) : tPath(); 
    164176  result.query = (match.size() > 7 && match[7].matched) ? match[7] : empty; 
    165177  result.fragment = (match.size() > 9 && match[9].matched) ? match[9] : empty; 
Note: See TracChangeset for help on using the changeset viewer.