Fix ExtName() function that is in common/file_utils.cc
authorjh5.cho <jh5.cho@samsung.com>
Wed, 30 Sep 2015 10:11:31 +0000 (19:11 +0900)
committerjh5.cho <jh5.cho@samsung.com>
Wed, 30 Sep 2015 10:11:31 +0000 (19:11 +0900)
  ExtName() function, which returns a file extension, was returning the wrong extention
  when there is '?' or '#' after a 'html' file path.

  (ex) If path is "file://abc.html?test=c", returned value was ".html?test=c".
       Now it is corrected to ".html"

common/file_utils.cc

index 8fa525339b08b5b32f7fbb7f480c469bf42ea5e7..47eb222a976e3e0476504f9c17801a1c662d76f0 100644 (file)
@@ -54,6 +54,9 @@ std::string ExtName(const std::string& path) {
   size_t last_dot = path.find_last_of(".");
   if (last_dot != 0 && last_dot != std::string::npos) {
     std::string ext = path.substr(last_dot);
+    size_t end_of_ext = ext.find_first_of("?#");
+    if (end_of_ext != std::string::npos)
+      ext = ext.substr(0, end_of_ext);
     std::transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
     return ext;
   } else {