Skip to content

Commit 32f44ac

Browse files
committed
feat: Sanitize user input with single quotes
1 parent 807046a commit 32f44ac

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bakta-web-backend"
3-
version = "0.6.3"
3+
version = "0.6.4"
44
edition = "2021"
55

66
[dependencies]

src/api_structs.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ pub struct JobConfig {
200200
pub compliant: bool,
201201
}
202202

203-
pub fn strip_whitespace(s: String) -> String {
204-
s.replace(" ", "")
203+
pub fn sanitize_input(s: String) -> String {
204+
format!("'{}'", s.replace("'", ""))
205205
}
206206

207207
impl JobConfig {
@@ -226,13 +226,13 @@ impl JobConfig {
226226

227227
if let Some(locus) = self.locus {
228228
if !locus.is_empty() {
229-
parameters.push(format!("--locus {}", strip_whitespace(locus)));
229+
parameters.push(format!("--locus {}", sanitize_input(locus)));
230230
}
231231
}
232232

233233
if let Some(locus_tag) = self.locus_tag {
234234
if !locus_tag.is_empty() {
235-
parameters.push(format!("--locus-tag {}", strip_whitespace(locus_tag)));
235+
parameters.push(format!("--locus-tag {}", sanitize_input(locus_tag)));
236236
}
237237
}
238238

@@ -242,25 +242,25 @@ impl JobConfig {
242242

243243
if let Some(genus) = self.genus {
244244
if !genus.is_empty() {
245-
parameters.push(format!("--genus {}", strip_whitespace(genus)));
245+
parameters.push(format!("--genus {}", sanitize_input(genus)));
246246
}
247247
}
248248

249249
if let Some(species) = self.species {
250250
if !species.is_empty() {
251-
parameters.push(format!("--species {}", strip_whitespace(species)));
251+
parameters.push(format!("--species {}", sanitize_input(species)));
252252
}
253253
}
254254

255255
if let Some(strain) = self.strain {
256256
if !strain.is_empty() {
257-
parameters.push(format!("--strain {}", strip_whitespace(strain)));
257+
parameters.push(format!("--strain {}", sanitize_input(strain)));
258258
}
259259
}
260260

261261
if let Some(plasmid) = self.plasmid {
262262
if !plasmid.is_empty() {
263-
parameters.push(format!("--plasmid {}", strip_whitespace(plasmid)));
263+
parameters.push(format!("--plasmid {}", sanitize_input(plasmid)));
264264
}
265265
}
266266

0 commit comments

Comments
 (0)