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

[#2209] Skip blank lines in blurb file url #2239

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Changes from 3 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
15 changes: 13 additions & 2 deletions src/main/java/reposense/parser/BlurbMarkdownParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public BlurbMap parse() throws IOException, InvalidMarkdownException {
// extract the url record first
// this is guaranteed to be in the first line or else we fail
UrlRecord urlRecord = this.getUrlRecord(mdLines, counter);
// if delimiter is the last non-blank line, null is returned
if (urlRecord == null) {
break;
}
url = urlRecord.getUrl();
counter = urlRecord.getNextPosition();

Expand Down Expand Up @@ -120,9 +124,16 @@ private UrlRecord getUrlRecord(List<String> lines, int position) throws InvalidM
// checks if url is valid
// adapted from https://www.baeldung.com/java-validate-url
try {
String url = lines.get(position).strip();
String url;
// skips blank lines
for (url = ""; url.length() == 0; url = lines.get(position++).strip()) {
// checks if delimiter is the last non-blank line
if (position >= lines.size()) {
return null;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This works well enough, but we can consider using a while loop, as the linear flow would make it easier to read.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to use a while loop

new URL(url).toURI();
return new UrlRecord(lines.get(position), position + 1);
return new UrlRecord(url, position);
} catch (MalformedURLException | URISyntaxException ex) {
throw new InvalidMarkdownException("URL provided is not valid!");
}
Expand Down
Loading