Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix macOS section handling that already have a comma in ther name #398

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ impl<'ctx> Value<'ctx> {

// On MacOS we need to remove ',' before section name
if cfg!(target_os = "macos") {
Some(unsafe { CStr::from_ptr(ptr.add(1)) })
let name = unsafe { CStr::from_ptr(ptr) };
let name_string = name.to_string_lossy();
let mut chars = name_string.chars();
if Some(',') == chars.next() {
Some(unsafe { CStr::from_ptr(ptr.add(1)) })
} else {
Some(name)
}
} else {
Some(unsafe { CStr::from_ptr(ptr) })
}
Expand All @@ -195,7 +202,7 @@ impl<'ctx> Value<'ctx> {
/// Sets the section of the global value
fn set_section(self, section: Option<&str>) {
#[cfg(target_os = "macos")]
let section = section.map(|s| format!(",{}", s));
let section = section.map(|s| if s.contains(",") { format!("{}", s) } else { format!(",{}", s) });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be starts_with?

Copy link
Contributor Author

@ptitSeb ptitSeb Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. the idea is if a section name is just "mystuff", it needs to be set as ",mystuff", but if it's "XXX,mystuff", then don't touch it.
Section are expected to be in the format <segment name>,<section name>, and it seems a no segment-name is acceptable, that why the previous commit added the ",".


let c_string = section.as_deref().map(to_c_str);

Expand Down