summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fc2d07b)
raw | patch | inline | side by side (parent: fc2d07b)
author | Junio C Hamano <junkio@cox.net> | |
Sun, 15 Apr 2007 21:56:09 +0000 (14:56 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 15 Apr 2007 22:49:41 +0000 (15:49 -0700) |
At the same time, we do not want to allow arbitrary strings for
attribute names, as we are likely to want to extend the syntax
later. Allow only alnum, dash, underscore and dot for now.
Signed-off-by: Junio C Hamano <junkio@cox.net>
attribute names, as we are likely to want to extend the syntax
later. Allow only alnum, dash, underscore and dot for now.
Signed-off-by: Junio C Hamano <junkio@cox.net>
attr.c | patch | blob | history | |
builtin-check-attr.c | patch | blob | history | |
t/t0020-crlf.sh | patch | blob | history |
index 410bca613cd83cb233889e50d0424f9e589c1ea0..60fe48f3b84d7dfa2d0e3f27852ceae03d7487d4 100644 (file)
--- a/attr.c
+++ b/attr.c
return val;
}
+static int invalid_attr_name(const char *name, int namelen)
+{
+ /*
+ * Attribute name cannot begin with '-' and from
+ * [-A-Za-z0-9_.]. We'd specifically exclude '=' for now,
+ * as we might later want to allow non-binary value for
+ * attributes, e.g. "*.svg merge=special-merge-program-for-svg"
+ */
+ if (*name == '-')
+ return -1;
+ while (namelen--) {
+ char ch = *name++;
+ if (! (ch == '-' || ch == '.' || ch == '_' ||
+ ('0' <= ch && ch <= '9') ||
+ ('a' <= ch && ch <= 'z') ||
+ ('A' <= ch && ch <= 'Z')) )
+ return -1;
+ }
+ return 0;
+}
+
struct git_attr *git_attr(const char *name, int len)
{
unsigned hval = hash_name(name, len);
return a;
}
+ if (invalid_attr_name(name, len))
+ return NULL;
+
a = xmalloc(sizeof(*a) + len + 1);
memcpy(a->name, name, len);
a->name[len] = 0;
* (1) glob pattern.
* (2) whitespace
* (3) whitespace separated list of attribute names, each of which
- * could be prefixed with '!' to mean "not set".
+ * could be prefixed with '-' to mean "not set".
*/
struct attr_state {
name += strlen(ATTRIBUTE_MACRO_PREFIX);
name += strspn(name, blank);
namelen = strcspn(name, blank);
+ if (invalid_attr_name(name, namelen)) {
+ fprintf(stderr,
+ "%.*s is not a valid attribute name: %s:%d\n",
+ namelen, name, src, lineno);
+ return NULL;
+ }
}
else
is_macro = 0;
while (*cp) {
const char *ep;
ep = cp + strcspn(cp, blank);
- if (pass) {
+ if (!pass) {
+ if (*cp == '-')
+ cp++;
+ if (invalid_attr_name(cp, ep - cp)) {
+ fprintf(stderr,
+ "%.*s is not a valid attribute name: %s:%d\n",
+ (int)(ep - cp), cp,
+ src, lineno);
+ return NULL;
+ }
+ } else {
struct attr_state *e;
e = &(res->state[num_attr]);
- if (*cp == '!') {
+ if (*cp == '-') {
e->unset = 1;
cp++;
}
sizeof(*res) +
sizeof(struct attr_state) * num_attr +
(is_macro ? 0 : namelen + 1));
- if (is_macro)
+ if (is_macro) {
res->u.attr = git_attr(name, namelen);
+ }
else {
res->u.pattern = (char*)&(res->state[num_attr]);
memcpy(res->u.pattern, name, namelen);
}
static const char *builtin_attr[] = {
- "[attr]binary !diff !crlf",
+ "[attr]binary -diff -crlf",
NULL,
};
diff --git a/builtin-check-attr.c b/builtin-check-attr.c
index 47b07210d61ad53c5d68e6c5dea767e2f52a131a..634be9ed2e4a28b0c3a53d8724bacbd3094b369d 100644 (file)
--- a/builtin-check-attr.c
+++ b/builtin-check-attr.c
check = xcalloc(cnt, sizeof(*check));
for (i = 0; i < cnt; i++) {
const char *name;
+ struct git_attr *a;
name = argv[i + 1];
- check[i].attr = git_attr(name, strlen(name));
+ a = git_attr(name, strlen(name));
+ if (!a)
+ return error("%s: not a valid attribute name", name);
+ check[i].attr = a;
}
for (i = doubledash; i < argc; i++) {
diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh
index 600dcd30a0184043f97854d340ac8b9340254205..cf84f0a1ab5b392930f1d5a0008530399a6a00f6 100755 (executable)
--- a/t/t0020-crlf.sh
+++ b/t/t0020-crlf.sh
test_expect_success '.gitattributes says two is binary' '
- echo "two !crlf" >.gitattributes &&
+ echo "two -crlf" >.gitattributes &&
rm -f tmp one dir/two &&
git repo-config core.autocrlf true &&
git read-tree --reset -u HEAD &&