about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2020-06-30 12:32:26 +0530
committerAndinus <andinus@nand.sh>2020-06-30 12:32:26 +0530
commit8dd9f42bfae6bb62b93b91f9c47ff410b12fa58b (patch)
treec4aa5f98164b15e10cc33a6ce5d4846bd2e0fbb5
parent420a084a2d6d28b4ece2f369c881965fe5ea89b8 (diff)
downloadcrux-8dd9f42bfae6bb62b93b91f9c47ff410b12fa58b.tar.gz
Fix logical error in $url generation
This issue started with f3d1bc5f9d86300c42d6a57a9f60bd508bdf9bb4:

  Use URI to encode the url for random_search

  I'll use this for everything eventually. Before this search terms
  like "rocky mountains" would break, also segments, query_keywords
  makes it easier.

Now the problem was that query_keywords forms urls like
`?nature+water' which totally makes sense & this is why it's logical
error. I want to form it in `?nature,water' format so first we use
`join' to form `nature,water' & then use URI::Encode to encode it
correctly & then use query_keywords to form $url.

We have to use URI::Encode because otherwise we would end up with same
problem that I tried fixing in
f3d1bc5f9d86300c42d6a57a9f60bd508bdf9bb4. "rocky mountains" would've
been seperated by space.

Now it's all good, every space will be encoded & keywords will be
seperated by `,' which is what Unsplash Source wants.
-rw-r--r--lib/UnsplashSource.pm5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/UnsplashSource.pm b/lib/UnsplashSource.pm
index e4c26aa..c41960e 100644
--- a/lib/UnsplashSource.pm
+++ b/lib/UnsplashSource.pm
@@ -8,6 +8,7 @@ use warnings;
 use URI;
 use HTTP::Tiny;
 use Carp qw( croak carp );
+use URI::Encode qw( uri_encode );
 
 my $api = "https://source.unsplash.com";
 my $http = HTTP::Tiny->new(
@@ -51,7 +52,7 @@ sub random_search {
     push @segments, $options{resolution};
     $url->path_segments( @segments );
 
-    $url->query_keywords( \@{$options{search}} );
+    $url->query_keywords( uri_encode(join(',', @{$options{search}})) );
 
     return $http->head($url);
 }
@@ -92,7 +93,7 @@ sub fixed {
     push @segments, "weekly" if $options{weekly};
     $url->path_segments( @segments );
 
-    $url->query_keywords( \@{$options{search}} );
+    $url->query_keywords( uri_encode(join(',', @{$options{search}})) );
 
     return $http->head($url);
 }
rtik.com> 2019-08-25 15:54:16 -0700 5582' href='/akkartik/mu/commit/html/065write-buffered.subx.html?h=hlt&id=6033844884f18c9a6e6e186c79c36fd1dd2c9bb0'>60338448 ^
ce2c1efc ^
695f9bf8 ^
60338448 ^
ce2c1efc ^
60338448 ^

ce2c1efc ^
60338448 ^
a94b60b5 ^















ce2c1efc ^
a94b60b5 ^















c8a3ccbe ^
a94b60b5 ^







2104d1a7 ^
ce2c1efc ^












33352536 ^





e99038ea ^
b1635a5c ^
33352536 ^

ce2c1efc ^
33352536 ^







2104d1a7 ^
33352536 ^
2104d1a7 ^
33352536 ^







ce2c1efc ^

33352536 ^
6070c23e ^
ce2c1efc ^
33352536 ^
6070c23e ^
ce2c1efc ^
33352536 ^
ce2c1efc ^

33352536 ^
ce2c1efc ^
999c529c ^
ce2c1efc ^
33352536 ^
ce2c1efc ^

33352536 ^

e99038ea ^
ce2c1efc ^
e99038ea ^
33352536 ^


ce2c1efc ^



33352536 ^

ce2c1efc ^
33352536 ^
ce2c1efc ^
33352536 ^
ce2c1efc ^
33352536 ^
4a4a392d ^
ce2c1efc ^

33352536 ^
ce2c1efc ^

33352536 ^





b1635a5c ^
33352536 ^

ce2c1efc ^










33352536 ^
8aeb85f0 ^
ce2c1efc ^
8aeb85f0 ^
999c529c ^






8aeb85f0 ^
999c529c ^





8aeb85f0 ^
999c529c ^









8aeb85f0 ^
999c529c ^














8aeb85f0 ^
999c529c ^
8aeb85f0 ^
999c529c ^








8aeb85f0 ^
999c529c ^






















8aeb85f0 ^
999c529c ^










fa786ea7 ^
7e7a8a6e ^
999c529c ^
8aeb85f0 ^
999c529c ^



695f9bf8 ^
999c529c ^








a94b60b5 ^



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291