Skip to content

Trim whitespace around the items of a comma-separated tag value - #138

Open
bercedev wants to merge 1 commit into
febiosoftware:developfrom
bercedev:fix/part-list-spaces
Open

bercedev wants to merge 1 commit into
febiosoftware:developfrom
bercedev:fix/part-list-spaces

Conversation

@bercedev

Copy link
Copy Markdown

Closes #137

XMLTag::value(std::vector<std::string>&) (and the overload that takes a count) split the tag value at commas but kept the whitespace around each item. <PartList> is the only place that reads a string list this way. A list written as Part1, Part2 asked for a part named Part2, FEBModel::BuildPart couldn't find that domain, and the model stopped with "Failed building parts."

Both overloads now take each item through a small listItem helper that trims spaces, tabs and line breaks around it. Spaces inside a name are kept. The helper builds a std::string, so items are no longer copied through the fixed char tmp[256] buffer, which overflowed for a name longer than 255 characters.

Testing

I didn't build all of FEBio or run a contact model. I compiled FECore/XMLReader.cpp with a small program (g++ 14, -std=c++17) that reads a <PartList> through XMLReader::OpenString and checks both overloads:

int main()
{
	int fails = 0;
	fails += check("Part1,Part2,Part3", {"Part1", "Part2", "Part3"});
	fails += check("Part1, Part2, Part3", {"Part1", "Part2", "Part3"});
	fails += check(" Part1 ,\tPart2 ,  Part3 ", {"Part1", "Part2", "Part3"});
	fails += check("Part1,Part2,Part with spaces", {"Part1", "Part2", "Part with spaces"});
	return fails;
}

With this change:

ok   [Part1,Part2,Part3] -> 'Part1' 'Part2' 'Part3'
ok   [Part1, Part2, Part3] -> 'Part1' 'Part2' 'Part3'
ok   [ Part1 ,	Part2 ,  Part3 ] -> 'Part1' 'Part2' 'Part3'
ok   [Part1,Part2,Part with spaces] -> 'Part1' 'Part2' 'Part with spaces'

On develop:

ok   [Part1,Part2,Part3] -> 'Part1' 'Part2' 'Part3'
FAIL [Part1, Part2, Part3] -> 'Part1' ' Part2' ' Part3'
FAIL [ Part1 ,	Part2 ,  Part3 ] -> ' Part1 ' ' Part2 ' '  Part3 '
ok   [Part1,Part2,Part with spaces] -> 'Part1' 'Part2' 'Part with spaces'

Note: I used Claude Code while working on this.

XMLTag::value(std::vector<std::string>&) kept the spaces after each comma, so a PartList written as "Part1, Part2" looked for a part named " Part2" and the model failed with "Failed building parts." The items are now trimmed, which also drops the 256-character buffer the items were copied into.

Closes febiosoftware#137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug report | Contact part lists fail to build if a space is used between names

1 participant