fix limit panicking in search() if config is specified
This commit is contained in:
parent
bf0c84f126
commit
c1483ab210
2 changed files with 9 additions and 8 deletions
12
src/api.rs
12
src/api.rs
|
@ -57,12 +57,12 @@ pub(crate) fn caps() -> status::Custom<RawXml<String>> {
|
||||||
pub(crate) fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf = create_empty_config();
|
let mut conf = create_empty_config();
|
||||||
unsafe {
|
unsafe {
|
||||||
if CONFIG.is_none() {
|
if CONFIG.is_none() {
|
||||||
return (*STATUS_CONFIG_NOT_SPECIFIED).clone();
|
return (*STATUS_CONFIG_NOT_SPECIFIED).clone();
|
||||||
} else {
|
} else {
|
||||||
let conf: Config = CONFIG.clone().ok_or("").unwrap();
|
conf = CONFIG.clone().ok_or("").unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,11 +99,9 @@ pub(crate) fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
offset = form.offset.ok_or(0).unwrap();
|
offset = form.offset.ok_or(0).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut limit: u32 = 0;
|
let mut limit: u32 = form.limit.ok_or("").unwrap_or(conf.caps.limits.max);
|
||||||
limit = conf.caps.limits.max;
|
if limit > conf.caps.limits.max {
|
||||||
let wanted_limit = form.limit.ok_or(limit).unwrap();
|
limit = conf.caps.limits.max;
|
||||||
if wanted_limit < limit {
|
|
||||||
limit = wanted_limit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
match conf.auth {
|
match conf.auth {
|
||||||
|
|
|
@ -54,7 +54,10 @@ pub(crate) fn create_empty_config() -> Config {
|
||||||
image: None,
|
image: None,
|
||||||
version: Some("1.0".to_string()),
|
version: Some("1.0".to_string()),
|
||||||
},
|
},
|
||||||
limits: Limits { max: 1, default: 1 },
|
limits: Limits {
|
||||||
|
max: 100,
|
||||||
|
default: 20,
|
||||||
|
},
|
||||||
searching: searching,
|
searching: searching,
|
||||||
categories: categories,
|
categories: categories,
|
||||||
genres: Some(genres),
|
genres: Some(genres),
|
||||||
|
|
Loading…
Reference in a new issue