Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

Commit 33aebd9

Browse files
committed
fix: query error
1 parent 16959d8 commit 33aebd9

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

src/custom/oauth.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,17 @@ pub fn server(port: u16) -> Result<impl AsyncSendSync<Result<Info, OAuthError>>,
105105
})
106106
}
107107

108-
109108
fn parse_info(data: &[u8]) -> Result<Info, OAuthError> {
110109
let data_str = std::str::from_utf8(data)
111110
.map_err(|_| OAuthError::ParseError("Invalid UTF-8".to_string()))?;
112111

113112
// Extract the query string from the HTTP request
114-
let query_start = data_str.find('?').ok_or_else(|| OAuthError::ParseError("No query string found".to_string()))?;
113+
let mut query_start = None;
114+
while query_start.is_none() {
115+
query_start = data_str.find('?');
116+
}
117+
let query_start =
118+
query_start.ok_or_else(|| OAuthError::ParseError("No query string found".to_string()))?;
115119
let query_end = data_str.find('#').unwrap_or_else(|| data_str.len());
116120
let query_string = &data_str[query_start + 1..query_end];
117121

@@ -121,7 +125,9 @@ fn parse_info(data: &[u8]) -> Result<Info, OAuthError> {
121125
.collect();
122126

123127
// Extract the 'code', 'state', 'error', and 'error_description' parameters
124-
let code = query_params.iter().find_map(|(k, v)| if k == "code" { Some(v.clone()) } else { None });
128+
let code = query_params
129+
.iter()
130+
.find_map(|(k, v)| if k == "code" { Some(v.clone()) } else { None });
125131
let state = query_params.iter().find_map(|(k, v)| {
126132
if k == "state" {
127133
// Find the position of "HTTP/1.1\r\n" in the state value
@@ -132,8 +138,16 @@ fn parse_info(data: &[u8]) -> Result<Info, OAuthError> {
132138
None
133139
}
134140
});
135-
let error = query_params.iter().find_map(|(k, v)| if k == "error" { Some(v.clone()) } else { None });
136-
let error_description = query_params.iter().find_map(|(k, v)| if k == "error_description" { Some(v.clone()) } else { None });
141+
let error = query_params
142+
.iter()
143+
.find_map(|(k, v)| if k == "error" { Some(v.clone()) } else { None });
144+
let error_description = query_params.iter().find_map(|(k, v)| {
145+
if k == "error_description" {
146+
Some(v.clone())
147+
} else {
148+
None
149+
}
150+
});
137151

138152
// Construct the Info struct
139153
let info = Info {
@@ -145,8 +159,6 @@ fn parse_info(data: &[u8]) -> Result<Info, OAuthError> {
145159
Ok(info)
146160
}
147161

148-
149-
150162
pub fn token(
151163
code: &str,
152164
client_id: &str,

0 commit comments

Comments
 (0)