Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: dbus/string_util.cc

Issue 10502011: Explicitly CHECK arguments in dbus::MessageWriter::AppendString/ObjectPath (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix wording Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "dbus/string_util.h"
6
7 #include "base/string_tokenizer.h"
8
9 namespace dbus {
10
11 bool IsStringValidObjectPath(const std::string& string) {
12 // This implementation is based upon D-Bus Specification Version 0.19.
13
14 // A valid object path begins with '/'.
15 if (string.empty())
16 return false;
17 if (string[0] != '/')
18 return false;
satorux1 2012/06/04 23:29:19 maybe if (!StartsWithAscii(value, "/", true))
hashimoto 2012/06/05 01:50:29 Done.
19
20 int element_length = 0;
satorux1 2012/06/04 23:29:19 might want to explain what element is. // Element
hashimoto 2012/06/05 01:50:29 Done.
21 for (size_t i = 1; i < string.length(); ++i) {
satorux1 2012/06/04 23:29:19 nit: .length() -> .size() as the former is more co
satorux1 2012/06/04 23:32:15 I meant the latter (size()) is more common.
hashimoto 2012/06/05 01:50:29 Done.
22 const char c = string[i];
23 if (c == '/') {
24 // No element separated by '/' may be the empty string.
25 if (element_length == 0)
26 return false;
27 element_length = 0;
28 } else {
29 // Each element must only contain "[A-Z][a-z][0-9]_".
30 const bool is_valid_character =
31 ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') ||
32 ('0' <= c && c <= '9') || c == '_';
33 if (!is_valid_character)
34 return false;
35 element_length++;
36 }
37 }
38
39 // A trailing '/' character is not allowed unless the path is the root path.
40 if (string.length() > 1 && string[string.length() - 1] == '/')
satorux1 2012/06/04 23:29:19 maybe if (value.size() > 1 && EndsWithASCII(value
hashimoto 2012/06/05 01:50:29 Done.
41 return false;
42
43 return true;
44 }
45
46 } // namespace dbus
OLDNEW
« dbus/string_util.h ('K') | « dbus/string_util.h ('k') | dbus/string_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698