[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Escapes in configuration (svn:ignore in dir-auto-props)

From: Ph. Marek <philipp.marek_at_bmlv.gv.at>
Date: 2005-04-04 10:33:31 CEST

Hello everybody,

here's a first patch to handle escapes in the configuration file.
I tried to keep it as simple as possible.

- May it cause problems, if a svn_string with len=8 has a \0 at index 4?
  Shall I disallow NULs?

- This clears the way for dir-auto-props; IIRC that was the last concern.

Questions, remarks welcome.

Regards,

Phil

[[[

Allow escape sequences in configuration files.

* subversion/include/svn_string.h
  (svn_stringbuf_do_backslash): New function.

* subversion/libsvn_subr/config_file.c
  (parse_option): Call svn_stringbuf_do_backslash for option.
  (parse_value): Call svn_stringbuf_do_backslash for value.

* subversion/libsvn_subr/svn_string.c
  (svn_stringbuf_do_backslash): New function.

]]]

=== subversion/libsvn_subr/svn_string.c
==================================================================
--- subversion/libsvn_subr/svn_string.c (/mirror/trunk) (revision 537)
+++ subversion/libsvn_subr/svn_string.c (/local/trunk) (revision 537)
@@ -388,6 +388,99 @@
 }

+/* returns 1 on success, 0 on error
+ * We allow \\, \000 (octal, 3 characters), \r, \n, and \x00 (2 characters) */
+int
+svn_stringbuf_do_backslash (svn_stringbuf_t *str)
+{
+ char *src, *dst;
+ int i;
+
+ src=dst=str->data;
+ while (*src)
+ {
+ if (src != dst)
+ *dst=*src;
+
+ if (*src == '\\')
+ {
+ src++;
+ str->len--;
+
+ switch (*src)
+ {
+ case '\\':
+ /* simply discard second \\ */
+ break;
+ case 'n':
+ *dst='\n';
+ break;
+ case 'r':
+ *dst='\r';
+ break;
+ case 'x':
+ src++;
+ /* I know isxdigit - but is there something that gives
+ * the value, too? sscanf seems too clumsy, and strtoi
+ * takes more characters, including an "0x" */
+ if (*src>='0' && *src<='9')
+ i=*src-'0';
+ else
+ if (*src>='a' && *src<='f')
+ i=*src-'a'+10;
+ else
+ if (*src>='A' && *src<='F')
+ i=*src-'A'+10;
+ else
+ return 0;
+ *dst=i << 4;
+
+ src++;
+ if (*src>='0' && *src<='9')
+ i=*src-'0';
+ else
+ if (*src>='a' && *src<='f')
+ i=*src-'a'+10;
+ else
+ if (*src>='A' && *src<='F')
+ i=*src-'A'+10;
+ else
+ return 0;
+ *dst |= i;
+ str->len -= 3; /* 4 chars got 1 */
+ break;
+ case '0' ... '3':
+ /* in octal we define the range 000 ... 377 */
+ *dst=(*src-'0') << 6;
+
+ src++;
+ if (*src>='0' && *src<='7')
+ *dst |= (*src-'0') << 3;
+ else
+ return 0;
+
+ src++;
+ if (*src>='0' && *src<='7')
+ *dst |= (*src-'0');
+ else
+ return 0;
+
+ str->len -= 3; /* 4 chars got 1 */
+ break;
+ default:
+ return 0;
+ }
+ }
+
+ src++;
+ dst++;
+ }
+
+ *dst='\0';
+ return 1;
+}
+
+
 void
 svn_stringbuf_appendstr (svn_stringbuf_t *targetstr,
                          const svn_stringbuf_t *appendstr)
=== subversion/libsvn_subr/config_file.c
==================================================================
--- subversion/libsvn_subr/config_file.c (/mirror/trunk) (revision 537)
+++ subversion/libsvn_subr/config_file.c (/local/trunk) (revision 537)
@@ -114,6 +114,18 @@
             {
               /* At end of file. The value is complete, there can't be
                  any continuation lines. */
+ if (!svn_stringbuf_do_backslash (ctx->value))
+ {
+ svn_error_t *err = SVN_NO_ERROR;
+
+ err = svn_error_createf (SVN_ERR_MALFORMED_FILE, NULL,
+ "%s:%d: invalid escape sequence (\\) in value",
+ svn_path_local_style (ctx->file,
+ ctx->cfg->pool),
+ ctx->line);
+ return err;
+ }
+
               svn_config_set (ctx->cfg, ctx->section->data,
                               ctx->option->data, ctx->value->data);
             }
@@ -190,6 +202,15 @@
       svn_stringbuf_appendbytes (ctx->option, &char_from_int, 1);
     }

+ if (!svn_stringbuf_do_backslash (ctx->option))
+ {
+ err = svn_error_createf (SVN_ERR_MALFORMED_FILE, NULL,
+ "%s:%d: invalid escape sequence (\\) in option name",
+ svn_path_local_style (ctx->file,
+ ctx->cfg->pool),
+ ctx->line);
+ }
+
   if (ch != ':' && ch != '=')
     {
       ch = EOF;
=== subversion/include/svn_string.h
==================================================================
--- subversion/include/svn_string.h (/mirror/trunk) (revision 537)
+++ subversion/include/svn_string.h (/local/trunk) (revision 537)
@@ -337,6 +337,14 @@
                   const char *separator,
                   apr_pool_t *pool);

+/** @since New in 1.2.
+ *
+ * Uses the escapes in @a str, and inserts "special" characters.
+ * Currently understood are \n, \r, \x?? (hex), and \??? (octal)
+ * \\ gives a "normal" backslash. */
+int
+svn_stringbuf_do_backslash (svn_stringbuf_t *str);
+
 /** @} */

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Apr 4 10:34:42 2005

This is an archived mail posted to the Subversion Dev mailing list.