[augeas-devel] [PATCH] Check that values match the regexp for the corresponding store during put
David Lutterkort
dlutter at redhat.com
Wed May 14 00:11:38 UTC 2008
2 files changed, 18 insertions(+), 2 deletions(-)
src/put.c | 15 +++++++++++++--
tests/modules/fail_put_bad_value.aug | 5 +++++
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1210720171 25200
# Node ID 23308c7b8a7b2cf3b059fb7d5517b1d534e187cc
# Parent 692913d849b78b92694f19da82b3a608a5d206a3
Check that values match the regexp for the corresponding store during put
diff -r 692913d849b7 -r 23308c7b8a7b src/put.c
--- a/src/put.c Tue May 13 16:02:30 2008 -0700
+++ b/src/put.c Tue May 13 16:09:31 2008 -0700
@@ -502,6 +502,17 @@ static void put_quant_maybe(struct lens
}
}
+static void put_store(struct lens *lens, struct state *state) {
+ if (regexp_match(lens->regexp, state->value, strlen(state->value),
+ 0, NULL) != strlen(state->value)) {
+ put_error(state, lens,
+ "Value '%s' does not match regexp /%s/ in store lens",
+ state->value, lens->regexp->pattern->str);
+ } else {
+ fprintf(state->out, "%s", state->value);
+ }
+}
+
static void put_lens(struct lens *lens, struct state *state) {
debug("put_lens: %s:%d %s\n", _t(lens), lens->info->first_line,
_l(state->tree));
@@ -513,7 +524,7 @@ static void put_lens(struct lens *lens,
put_del(lens, state);
break;
case L_STORE:
- fprintf(state->out, "%s", state->value);
+ put_store(lens, state);
break;
case L_KEY:
fprintf(state->out, "%s", state->key);
@@ -625,7 +636,7 @@ static void create_lens(struct lens *len
create_del(lens, state);
break;
case L_STORE:
- fprintf(state->out, "%s", state->value);
+ put_store(lens, state);
break;
case L_KEY:
fprintf(state->out, "%s", state->key);
diff -r 692913d849b7 -r 23308c7b8a7b tests/modules/fail_put_bad_value.aug
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/fail_put_bad_value.aug Tue May 13 16:09:31 2008 -0700
@@ -0,0 +1,5 @@
+module Fail_put_bad_value =
+
+ let lns = [ key /a/ . del /=/ "=" . store /[0-9]+/ ]
+
+ test lns put "a=20" after set "a" "foo" = ?
More information about the augeas-devel
mailing list