Skip to content

Commit 6311078

Browse files
committed
Strip more encoding modifiers
Strip modifiers even if they are inside the encoding string. Fixes #834
1 parent 1c95ea7 commit 6311078

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

crates/objc2-encode/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1818
### Fixed
1919
* Relaxed assertions on `Encoding::Struct`/`Encoding::Union`'s name to allow
2020
unicode identifiers.
21+
* Strip more modifiers to allow encoding parsing to work on macOS 10.7.
2122

2223

2324
## [4.1.0] - 2025-01-22

crates/objc2-encode/src/encoding.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ impl Encoding {
254254
pub fn equivalent_to_str(&self, s: &str) -> bool {
255255
let mut parser = Parser::new(s);
256256

257-
parser.strip_leading_qualifiers();
258-
259257
if let Some(()) = parser.expect_encoding(self, NestingLevel::new()) {
260258
// if the given encoding can be successfully removed from the
261259
// start and an empty string remains, they were fully equivalent!
@@ -784,6 +782,17 @@ mod tests {
784782
!"*c";
785783
!"^^c";
786784
}
785+
786+
// Regression test for https://github.com/madsmtm/objc2/issues/834.
787+
fn modifiers_behind_pointers() {
788+
Encoding::Pointer(&Encoding::Object);
789+
"^@";
790+
~"^r@";
791+
~"rrr^rrrr@";
792+
!"^^r@";
793+
!"r@";
794+
!"^@r"; // Unsure?
795+
}
787796
}
788797
789798
#[test]

crates/objc2-encode/src/encoding_box.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ impl EncodingBox {
124124
/// Returns an error if the string was an ill-formatted encoding string.
125125
pub fn from_start_of_str(s: &mut &str) -> Result<Self, ParseError> {
126126
let mut parser = Parser::new(s);
127-
parser.strip_leading_qualifiers();
128-
129127
match parser.parse_encoding_or_none() {
130128
Err(ErrorKind::Unknown(b'0'..=b'9')) => {
131129
let remaining = parser.remaining();
@@ -168,8 +166,6 @@ impl FromStr for EncodingBox {
168166

169167
fn from_str(s: &str) -> Result<Self, Self::Err> {
170168
let mut parser = Parser::new(s);
171-
parser.strip_leading_qualifiers();
172-
173169
parser
174170
.parse_encoding_or_none()
175171
.and_then(|enc| parser.expect_empty().map(|()| enc))

crates/objc2-encode/src/parse.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'a> Parser<'a> {
181181

182182
impl Parser<'_> {
183183
/// Strip leading qualifiers, if any.
184-
pub(crate) fn strip_leading_qualifiers(&mut self) {
184+
fn strip_leading_qualifiers(&mut self) {
185185
// TODO: Add API for accessing and outputting qualifiers.
186186
#[allow(clippy::byte_char_slices)]
187187
const QUALIFIERS: &[u8] = &[
@@ -270,6 +270,8 @@ impl Parser<'_> {
270270
}
271271

272272
pub(crate) fn expect_encoding(&mut self, enc: &Encoding, level: NestingLevel) -> Option<()> {
273+
self.strip_leading_qualifiers();
274+
273275
match enc.helper() {
274276
Helper::Primitive(primitive) => {
275277
match primitive {
@@ -426,6 +428,8 @@ impl Parser<'_> {
426428
}
427429

428430
fn parse_inner(&mut self) -> Result<ParseInner> {
431+
self.strip_leading_qualifiers();
432+
429433
if self.is_empty() {
430434
return Ok(ParseInner::Empty);
431435
}

0 commit comments

Comments
 (0)