Skip to content

Instantly share code, notes, and snippets.

@pierrejoye
Created September 7, 2011 14:19
Show Gist options
  • Select an option

  • Save pierrejoye/1200686 to your computer and use it in GitHub Desktop.

Select an option

Save pierrejoye/1200686 to your computer and use it in GitHub Desktop.
Index: Zend/zend_API.c
===================================================================
--- Zend/zend_API.c (revision 316345)
+++ Zend/zend_API.c (working copy)
@@ -442,7 +442,35 @@
if (c == 'p') {
/* do not allow trailing space (or single, */
if (Z_STRVAL_PP(arg)[0] == ' ' || Z_STRVAL_PP(arg)[Z_STRLEN_PP(arg) - 1] == ' ') {
- return "a valid path";
+ register int x = 0, y = 0, cur;
+ const int arg_len = Z_STRLEN_PP(arg);
+ const int arg_last = Z_STRLEN_PP(arg);
+ int trailing = 1;
+ char *esc;
+ char *str = Z_STRVAL_PP(arg);
+ size_t estimate = (2 * arg_len) + 1;
+
+ esc = safe_emalloc(2, arg_len, 1);
+ for (x = 0, y = 0; x < arg_len; x++) {
+ if (str[x] == ' ') {
+ esc[y++] = '^';
+ esc[y++] = ' ';
+ } else {
+ break;
+ }
+ }
+
+ cur = arg_last;
+ while (str[--cur] == ' ');
+
+ memcpy(esc + y, str + x, cur - x + 1);
+ y += cur - x + 1;
+ for (x = cur - 1; x < arg_len; x++) {
+ esc[y++] = '^';
+ esc[y++] = ' ';
+ }
+ esc[y] = '\0';
+
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment