Skip to content

Commit 6307c50

Browse files
cursoragentlovasoa
andcommitted
Refactor: Use String::from_utf8_lossy for SSRP response parsing
Co-authored-by: contact <contact@ophir.dev>
1 parent 2a08336 commit 6307c50

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

  • sqlx-core/src/mssql/connection

sqlx-core/src/mssql/connection/ssrp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::error::Error;
22
use sqlx_rt::{timeout, UdpSocket};
3+
use std::borrow::Cow;
34
use std::collections::HashMap;
45
use std::time::Duration;
56

@@ -87,15 +88,14 @@ pub(crate) async fn resolve_instance_port(server: &str, instance: &str) -> Resul
8788
));
8889
}
8990

90-
let response_data = String::from_utf8(buffer[3..(3 + response_size)].to_vec())
91-
.map_err(|e| err_protocol!("SSRP response is not valid UTF-8: {}", e))?;
91+
let response_data = String::from_utf8_lossy(&buffer[3..(3 + response_size)]);
9292

9393
log::debug!("SSRP response data: {}", response_data);
9494

9595
parse_ssrp_response(&response_data, instance)
9696
}
9797

98-
fn parse_ssrp_response(data: &str, instance_name: &str) -> Result<u16, Error> {
98+
fn parse_ssrp_response(data: &Cow<'_, str>, instance_name: &str) -> Result<u16, Error> {
9999
let instances: Vec<&str> = data.split(";;").collect();
100100
log::debug!(
101101
"parsing SSRP response, found {} instance entries",

0 commit comments

Comments
 (0)