Use built-in URL modifying methods instead of string concat when crea… #196
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ting paths.
The
FileIterator
class was using string concat to combine strings into file paths. This isn't very resilient to different types of valid input. The built-in file URL modifying methods (e.g. appendingPathComponent...) are more resilient.This manifested as an error when trying to format a directory, where I included a trailing
/
in the directory path passed to swift-format. That/
resulted inFileIterator
working on paths that included 2/
characters. Later on,deleteLastPathComponent
handles the paths with 2/
characters by appending../
. Eventually, this leads to an infinite loop of appending../
to the search path when searching for configuration files.I compared the performance of this implementation with the previous implementation. There wasn't a notable difference. I tested by recursively formatting the swift-protobuf repo: