Klaus Demo nginx / e115841
Added ngx_filename_cmp() with "/" sorted to the left. This patch fixes incorrect handling of auto redirect in configurations like: location /0 { } location /a- { } location /a/ { proxy_pass ... } With previously used sorting, this resulted in the following locations tree (as "-" is less than "/"): "/a-" "/0" "/a/" and a request to "/a" didn't match "/a/" with auto_redirect, as it didn't traverse relevant tree node during lookup (it tested "/a-", then "/0", and then falled back to null location). To preserve locale use for non-ASCII characters on case-insensetive systems, libc's tolower() used. Maxim Dounin 8 years ago
10 changed file(s) with 51 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
852852
853853
854854 ngx_int_t
855 ngx_filename_cmp(u_char *s1, u_char *s2, size_t n)
856 {
857 ngx_uint_t c1, c2;
858
859 while (n) {
860 c1 = (ngx_uint_t) *s1++;
861 c2 = (ngx_uint_t) *s2++;
862
863 #if (NGX_HAVE_CASELESS_FILESYSTEM)
864 c1 = tolower(c1);
865 c2 = tolower(c2);
866 #endif
867
868 if (c1 == c2) {
869
870 if (c1) {
871 n--;
872 continue;
873 }
874
875 return 0;
876 }
877
878 /* we need '/' to be the lowest character */
879
880 if (c1 == 0 || c2 == 0) {
881 return c1 - c2;
882 }
883
884 c1 = (c1 == '/') ? 0 : c1;
885 c2 = (c2 == '/') ? 0 : c2;
886
887 return c1 - c2;
888 }
889
890 return 0;
891 }
892
893
894 ngx_int_t
855895 ngx_atoi(u_char *line, size_t n)
856896 {
857897 ngx_int_t value;
166166 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
167167 ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
168168 ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
169 ngx_int_t ngx_filename_cmp(u_char *s1, u_char *s2, size_t n);
169170
170171 ngx_int_t ngx_atoi(u_char *line, size_t n);
171172 ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
1919 #include <stddef.h> /* offsetof() */
2020 #include <stdio.h>
2121 #include <stdlib.h>
22 #include <ctype.h>
2223 #include <errno.h>
2324 #include <string.h>
2425 #include <signal.h>
191191 void ngx_close_file_mapping(ngx_file_mapping_t *fm);
192192
193193
194 #if (NGX_HAVE_CASELESS_FILESYSTEM)
195
196 #define ngx_filename_cmp(s1, s2, n) strncasecmp((char *) s1, (char *) s2, n)
197
198 #else
199
200 #define ngx_filename_cmp ngx_memcmp
201
202 #endif
203
204
205194 #define ngx_realpath(p, r) (u_char *) realpath((char *) p, (char *) r)
206195 #define ngx_realpath_n "realpath()"
207196 #define ngx_getcwd(buf, size) (getcwd((char *) buf, size) != NULL)
1515 #include <stddef.h> /* offsetof() */
1616 #include <stdio.h>
1717 #include <stdlib.h>
18 #include <ctype.h>
1819 #include <errno.h>
1920 #include <string.h>
2021 #include <signal.h>
2121 #include <stddef.h> /* offsetof() */
2222 #include <stdio.h>
2323 #include <stdlib.h>
24 #include <ctype.h>
2425 #include <errno.h>
2526 #include <string.h>
2627 #include <signal.h>
3838 #include <stddef.h> /* offsetof() */
3939 #include <stdio.h>
4040 #include <stdlib.h>
41 #include <ctype.h>
4142 #include <errno.h>
4243 #include <string.h>
4344 #include <signal.h>
2121 #include <stddef.h> /* offsetof() */
2222 #include <stdio.h>
2323 #include <stdlib.h>
24 #include <ctype.h>
2425 #include <errno.h>
2526 #include <string.h>
2627 #include <signal.h>
171171 void ngx_close_file_mapping(ngx_file_mapping_t *fm);
172172
173173
174 #define NGX_HAVE_CASELESS_FILESYSTEM 1
175
176 #define ngx_filename_cmp(s1, s2, n) _strnicmp((char *) s1, (char *) s2, n)
177
178
179174 u_char *ngx_realpath(u_char *path, u_char *resolved);
180175 #define ngx_realpath_n ""
181176 #define ngx_getcwd(buf, size) GetCurrentDirectory(size, (char *) buf)
4444 #include <stdio.h>
4545 #include <stdlib.h>
4646 #include <stdarg.h>
47 #include <ctype.h>
4748 #include <locale.h>
4849
4950 #ifdef __WATCOMC__
122123 typedef __int32 int32_t;
123124 typedef unsigned __int16 uint16_t;
124125 #define ngx_libc_cdecl __cdecl
125 #define _strnicmp strnicmp
126126
127127 #else /* __WATCOMC__ */
128128 typedef unsigned int uint32_t;
195195 #define NGX_HAVE_INHERITED_NONBLOCK 1
196196 #endif
197197
198 #ifndef NGX_HAVE_CASELESS_FILESYSTEM
199 #define NGX_HAVE_CASELESS_FILESYSTEM 1
200 #endif
201
198202 #ifndef NGX_HAVE_WIN32_TRANSMITPACKETS
199203 #define NGX_HAVE_WIN32_TRANSMITPACKETS 1
200204 #define NGX_HAVE_WIN32_TRANSMITFILE 0