agoo 2.15.2 → 2.15.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad246b7aa0e634eff81c6c9bdec4d3567115a3beb8b6c237e25f87215fc2dbe3
4
- data.tar.gz: 03b6217fd351024938607dd036dcfd437a0dd967b22eca2b51aa0ed8a041d969
3
+ metadata.gz: 198dedaa66484abc8e37d6eb0ed4dcafb8ca02c2a55dc22c64c276368133e3b7
4
+ data.tar.gz: 37bdd47c51df1bdda5455363cbde76953ea508ec36183c0d88658e4d6f68defc
5
5
  SHA512:
6
- metadata.gz: a244ea77e0f13688e2e6237c31eb320af4c0eeb9780f6023ef6337db7f64839ce543a27d5890155fb0908f0ce6567733b750be0d7b7c4de246430c54a736b6f4
7
- data.tar.gz: abf7f274c15852b21b64ac6018b03264d08968902b9ad71d4f56d84a5ea34cf018b5e26daf6bde44f7f748da57a889c373435658cfb085ff537f3a683433c6d3
6
+ metadata.gz: 251b917392fe0b1e3d8ce11c92e713350eda58d3a28ee6eaa3ba67fbecaf6174aa7f76d50fe70b6b69e02711bde4f185bbcf698feab0d89c89f269066ec63986
7
+ data.tar.gz: 532befc3ea42c1d0aae87c4b8ee5f06a4973948bad456beb162edec702cbf49c84f4dbe39a9af5aa46bfc70e49026d7a9b44aa0e9b29e74286fa0f8cbadb34af
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  All changes to the Agoo gem are documented here. Releases follow semantic versioning.
4
4
 
5
+ ## [2.15.3] - 2022-09-23
6
+
7
+ ### Fixed
8
+
9
+ - Asset names with spaces or special characters are now loaded correctly.
10
+
5
11
  ## [2.15.2] - 2022-06-21
6
12
 
7
13
  ### Fixed
data/ext/agoo/page.c CHANGED
@@ -110,6 +110,16 @@ static struct _mime mime_map[] = {
110
110
 
111
111
  static const char page_fmt[] = "HTTP/1.1 200 OK\r\nContent-Type: %s\r\nContent-Length: %ld\r\n\r\n";
112
112
  static const char page_min_fmt[] = "HTTP/1.1 200 OK\r\nContent-Length: %ld\r\n";
113
+ // 0123456789abcdef0123456789abcdef
114
+ static const char hex_map[] = "\
115
+ ................................\
116
+ ................\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09......\
117
+ .\x0a\x0b\x0c\x0d\x0e\x0f.........................\
118
+ .\x0a\x0b\x0c\x0d\x0e\x0f.........................\
119
+ ................................\
120
+ ................................\
121
+ ................................\
122
+ ................................";
113
123
 
114
124
  static struct _cache cache = {
115
125
  .buckets = {0},
@@ -120,29 +130,35 @@ static struct _cache cache = {
120
130
  .head_rules = NULL,
121
131
  };
122
132
 
133
+ static char
134
+ parse_percent_seq(const char *seq) {
135
+ const char *end = seq + 2;
136
+ uint8_t h;
137
+ uint8_t b = 0;
138
+
139
+ for (; seq < end; seq++) {
140
+ if (16 < (h = hex_map[(uint8_t)*seq])) {
141
+ return '?';
142
+ }
143
+ b = (b << 4) | h;
144
+ }
145
+ return (char)b;
146
+ }
147
+
123
148
  static uint64_t
124
149
  calc_hash(const char *key, int *lenp) {
125
150
  int len = 0;
126
151
  int klen = *lenp;
127
152
  uint64_t h = 0;
128
- bool special = false;
129
153
  const uint8_t *k = (const uint8_t*)key;
130
154
 
131
155
  for (; len < klen; k++) {
132
- // narrow to most used range of 0x4D (77) in size
133
- if (*k < 0x2D || 0x7A < *k) {
134
- special = true;
135
- }
136
156
  // fast, just spread it out
137
157
  h = 77 * h + (*k - 0x2D);
138
158
  len++;
139
159
  }
160
+ *lenp = len;
140
161
 
141
- if (special) {
142
- *lenp = -len;
143
- } else {
144
- *lenp = len;
145
- }
146
162
  return h;
147
163
  }
148
164
 
@@ -790,9 +806,25 @@ agoo_page_get(agooErr err, const char *path, int plen, const char *root) {
790
806
  if ('/' != *root && '/' != *(s - 1) && '/' != *path) {
791
807
  *s++ = '/';
792
808
  }
793
- strncpy(s, path, plen);
794
- s[plen] = '\0';
795
-
809
+ // TBD if path has % then ...
810
+ if (NULL != memchr(path, '%', plen)) {
811
+ const char *pend = path + plen;
812
+ const char *pp = path;
813
+
814
+ for (; pp < pend; pp++) {
815
+ if ('%' != *pp) {
816
+ *s++ = *pp;
817
+ continue;
818
+ }
819
+ *s++ = parse_percent_seq(pp+1);
820
+ pp += 2;
821
+ }
822
+ } else {
823
+ strncpy(s, path, plen);
824
+ s += plen;
825
+ }
826
+ *s = '\0';
827
+ plen = (int)(s - full_path);
796
828
  if (NULL == (page = cache_root_get(full_path, plen))) {
797
829
  if (NULL != cache.root) {
798
830
  agooPage old;
@@ -815,10 +847,12 @@ agoo_page_get(agooErr err, const char *path, int plen, const char *root) {
815
847
  }
816
848
  } else {
817
849
  if (NULL == (page = cache_get(path, plen))) {
818
- if (NULL != cache.root) {
850
+ bool has_percent = NULL != memchr(path, '%', plen);
851
+
852
+ if (NULL != cache.root || has_percent) {
819
853
  agooPage old;
820
- char full_path[2048];
821
- char *s = stpcpy(full_path, cache.root);
854
+ char full_path[2048];
855
+ char *s = stpcpy(full_path, cache.root);
822
856
 
823
857
  if ('/' != *cache.root && '/' != *path) {
824
858
  *s++ = '/';
@@ -827,17 +861,34 @@ agoo_page_get(agooErr err, const char *path, int plen, const char *root) {
827
861
  AGOO_ERR_MEM(err, "Page path");
828
862
  return NULL;
829
863
  }
830
- strncpy(s, path, plen);
831
- s[plen] = '\0';
832
- if (NULL == (page = agoo_page_create(full_path))) {
864
+ if (has_percent) {
865
+ const char *pend = path + plen;
866
+ const char *pp = path;
867
+
868
+ for (; pp < pend; pp++) {
869
+ if ('%' != *pp) {
870
+ *s++ = *pp;
871
+ continue;
872
+ }
873
+ *s++ = parse_percent_seq(pp+1);
874
+ pp += 2;
875
+ }
876
+ *s = '\0';
877
+ } else {
878
+ strncpy(s, path, plen);
879
+ s[plen] = '\0';
880
+ }
881
+ if (NULL == (page = agoo_page_create(full_path))) { // TBD full_path or original path?
833
882
  AGOO_ERR_MEM(err, "Page");
834
883
  return NULL;
835
884
  }
885
+ plen = (int)strlen(full_path);
836
886
  if (!update_contents(page) || NULL == page->resp) {
837
887
  agoo_page_destroy(page);
838
888
  agoo_err_set(err, AGOO_ERR_NOT_FOUND, "not found.");
839
889
  return NULL;
840
890
  }
891
+ // Cache key is the original path/plen.
841
892
  if (NULL != (old = cache_set(path, plen, page))) {
842
893
  agoo_page_destroy(old);
843
894
  }
data/lib/agoo/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Agoo
3
3
  # Agoo version.
4
- VERSION = '2.15.2'
4
+ VERSION = '2.15.3'
5
5
  end
data/test/static_test.rb CHANGED
@@ -69,6 +69,25 @@ class StaticTest < Minitest::Test
69
69
  assert_equal(expect, content)
70
70
  end
71
71
 
72
+ def test_fetch_space_name
73
+ uri = URI('http://localhost:6469/space%20in%20name.html')
74
+ expect = %|<!DOCTYPE html>
75
+ <html>
76
+ <head><title>Agoo Space Test</title></head>
77
+ <body>Agoo</body>
78
+ </html>
79
+ |
80
+ req = Net::HTTP::Get.new(uri)
81
+ req['Accept-Encoding'] = '*'
82
+ req['User-Agent'] = 'Ruby'
83
+ res = Net::HTTP.start(uri.hostname, uri.port) { |h|
84
+ h.request(req)
85
+ }
86
+ content = res.body
87
+ assert_equal('text/html', res['Content-Type'])
88
+ assert_equal(expect, content)
89
+ end
90
+
72
91
  def test_mime
73
92
  uri = URI('http://localhost:6469/odd.odd')
74
93
  req = Net::HTTP::Get.new(uri)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: agoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.15.2
4
+ version: 2.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Ohler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-21 00:00:00.000000000 Z
11
+ date: 2022-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj