Hi,
Here a thin patch for vanilla 2.2.14 to strip comments when reading config
files. Without
it, you can't comment inline your config nor disable a pattern for rapid
tests. In fact, this only have impact with command type AP_INIT_TAKE_ARGV like :
IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=*
Charset=UTF-8 # Look nicer
IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=*
# Charset=UTF-8 # Look nicer
Attached patch allow you to strip that as the regexp .*[^"].*(( |\t)+)#.*
to :
- Avoid strip unblank pre-sharp character, only strip when preceding by
space or tab
IndexIgnore .??* *~ *# Not stripped part
- Also, handle multiline when using \
IndexOptions FancyIndexing \ # That is stripped
VersionSort \ # And
that too
...
So AP_INIT_TAKE_ARGV (and others now) only see real config and no more comments.
As I can't find any "No "get string" function", I didn't do it for that way.
I think for patch is simple but hey, it's my first attempt to hack a
bit apache. I'd appreciate comments, reviews, and if it need to be applied
to "No "get string" function" part.
Bertrand
--
Bertrand Jacquin, EXOSEC (http://www.exosec.fr/)
ZAC des Metz - 3 Rue du petit robinson - 78350 JOUY EN JOSAS
Tel: +33 1 30 67 60 65 - Fax: +33 1 75 43 40 70
mailto:[email protected]
--- server/util.c.ori 2010-01-27 15:39:03.000000000 +0100
+++ server/util.c 2010-01-27 20:27:38.000000000 +0100
@@ -1004,6 +1004,7 @@ AP_DECLARE(int) ap_cfg_getline(char *buf
char *src, *dst;
char *cp;
char *cbuf = buf;
+ char flag;
size_t cbufsize = bufsize;
while (1) {
@@ -1011,6 +1012,44 @@ AP_DECLARE(int) ap_cfg_getline(char *buf
if (cfp->getstr(cbuf, cbufsize, cfp->param) == NULL)
return 1;
+ /* Strip comments
+ * match .*[^"].*(( |\t)+)#.*
+ */
+ for (cp = cbuf, flag = 0 ; cp < cbuf+cbufsize ; cp++) {
+ /* Don't search while in unescaped quote */
+ if (cp > cbuf && (cp[-1] != '\\' && *cp == '"')) {
+ flag |= 0x1;
+ }
+
+ /* Ensure the quote is closed */
+ if ((flag & 0x1) % 2) {
+ continue;
+ }
+
+ /* If a sharp is there
+ * Ensure it's preceded with space or tab
+ */
+ if ( *cp == '#'
+ && (cp > cbuf ? (cp[-1] == ' ' || cp[-1] == '\t') : 1)
+ ) {
+ /* Erase #.* */
+ for ( ; *cp != '\0' ; cp++) {
+ *cp = ' ';
+ }
+
+ /* Back to end of config line */
+ while (cp >= cbuf && (*cp == ' ' || *cp == '\t' || *cp == '\0')) {
+ --cp;
+ }
+
+ /* Pseudo terminate it */
+ cp[1] = '\n';
+ cp[2] = '\0';
+
+ break;
+ }
+ }
+
/*
* check for line continuation,
* i.e. match [^\\]\\[\r]\n only