#include <boost/algorithm/string.hpp>
#include <vector>
-#include "manifest_parser/utils/logging.h"
#include "manifest_parser/utils/w3c_languages.h"
namespace ba = boost::algorithm;
namespace utils {
namespace w3c_languages {
-bool ValidateLanguageTag(const std::string& tag) {
- // algorithm based on http://www.w3.org/International/articles/language-tags/
+// algorithm based on http://www.w3.org/International/articles/language-tags/
+bool ValidateLanguageTag(const std::string& tag, std::string* error) {
std::vector<std::string> splitted_tag;
if (tag.empty()) {
- LOG(ERROR) << "tag is empty";
+ if (error)
+ *error = "tag is empty";
return false;
}
boost::split(splitted_tag, tag, boost::is_any_of(kTagDelimiter));
// main language validation
if (current_item != splitted_tag.end() &&
!lang_set::ValidateOnlyLanguage(*current_item)) {
- LOG(ERROR) << "Invalid main language tag given";
+ if (error)
+ *error = "Invalid main language tag given";
return false;
}
++current_item;
if (current_item == splitted_tag.end())
return true;
} else {
- LOG(ERROR) << "Extlang does not match language";
+ if (error)
+ *error = "Extlang does not match language";
return false;
}
}
}
// extension private tag validation
if ((*current_item).size() != kSingletonTagSize) {
- LOG(ERROR) << "Singletion subtag should be of size " << kSingletonTagSize;
+ if (error)
+ *error = std::string("Singletion subtag should be of size ") +
+ std::to_string(kSingletonTagSize);
return false;
}
++current_item;
for (auto it = current_item; it != splitted_tag.end(); ++current_item) {
auto tag_length = (*current_item).size();
if (tag_length > kMaximumExtensionTagSize) {
- LOG(ERROR) << "Any extensions should be maximum "
- << kMaximumExtensionTagSize << "characters";
+ if (error)
+ *error = std::string("Any extensions should be maximum ") +
+ std::to_string(kMaximumExtensionTagSize) + "characters";
return false;
}
}
* - http://www.w3.org/International/articles/language-tags/
*
* @param language tag string
+ * @param error output parameter for error
* @return true if tag is correct
*/
-bool ValidateLanguageTag(const std::string& tag);
+bool ValidateLanguageTag(const std::string& tag, std::string* error = nullptr);
} // namespace w3c_languages
} // namespace utils
#include "manifest_parser/manifest_handler.h"
#include "manifest_parser/utils/iri_util.h"
+#include "manifest_parser/utils/language_tag_validator.h"
#include "manifest_parser/utils/logging.h"
#include "wgt_manifest_handlers/account_handler.h"
#include "wgt_manifest_handlers/app_control_handler.h"
std::vector<std::string> path_components;
ba::split(path_components, content_value, ba::is_any_of("/"));
if (path_components.size() >= 1 && path_components[0] == kLocaleDirectory) {
- if (path_components.size() == 1) {
+ if (path_components.size() == 1)
return FindResult::NUL;
- }
- // TODO(t.iwanek): validate language tag
+ if (!utils::w3c_languages::ValidateLanguageTag(path_components[1]))
+ return FindResult::NUL;
path_components.erase(path_components.begin(), ++++path_components.begin());
content_value = ba::join(path_components, "/");
iter != bf::directory_iterator(); ++iter) {
const bf::path& path = *iter;
- // TODO(t.iwanek): validate language tag
+ if (!utils::w3c_languages::ValidateLanguageTag(path.filename().string()))
+ continue;
bf::path candidate = path / content_value;
if (bf::exists(candidate, error)) {