From 1acbe1b8561a3b9414ead9a85f9abd7c31208331 Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Wed, 9 Oct 2024 12:20:45 +0200 Subject: [PATCH] Properly ignore whitespace when parsing JSON arrays and objects --- firmware/src/json/reader.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/src/json/reader.rs b/firmware/src/json/reader.rs index c8a9504..53b764c 100644 --- a/firmware/src/json/reader.rs +++ b/firmware/src/json/reader.rs @@ -53,7 +53,6 @@ impl Reader { /// large objects or arrays, this may allocate a lot memory. See `read_object` and `read_array` /// for memory-optimized streaming read of objects and arrays. pub async fn read_any(&mut self) -> Result> { - self.trim().await?; match self.peek().await? { b'{' => Ok(Value::Object(Box::pin(self.read()).await?)), b'[' => Ok(Value::Array(Box::pin(self.read()).await?)), @@ -73,12 +72,13 @@ impl Reader { &mut self, mut f: impl FnMut(String, T) -> Result<(), Error>, ) -> Result<(), Error> { - self.trim().await?; self.expect(b'{').await?; loop { self.trim().await?; let key = self.read_string().await?; + self.trim().await?; self.expect(b':').await?; + self.trim().await?; let value = self.read().await?; f(key, value)?; self.trim().await?; @@ -101,9 +101,9 @@ impl Reader { &mut self, mut f: impl FnMut(T) -> Result<(), Error>, ) -> Result<(), Error> { - self.trim().await?; self.expect(b'[').await?; loop { + self.trim().await?; let elem = self.read().await?; f(elem)?; self.trim().await?;