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

BUGFIX: Fix array of strings parsing for coding contracts #937

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

rocket3989
Copy link
Contributor

@rocket3989 rocket3989 commented Nov 19, 2023

When a contract expects an array of strings, and the user manually submits it, parsing fails for arrays with spaces after the commas

e.g:

["()()()", "(())()"]
          ^

This is problematic because the examples for the coding contract show the strings formatted in this way:

image

Most common scripting languages will also by default format arrays in this way, so this error will happen to anyone directly pasting from them

The issue is that removeQuotesFromString will only remove quotes if they are either the first or last char in the string, so if there is whitespace at the start of the string before a quote, it will not remove it.

function removeQuotesFromString(str: string): string {
let strCpy: string = str;
if (strCpy.startsWith('"') || strCpy.startsWith("'")) {
strCpy = strCpy.slice(1);
}
if (strCpy.endsWith('"') || strCpy.endsWith("'")) {
strCpy = strCpy.slice(0, -1);
}
return strCpy;
}

The current flow for answer validation is:
split on ',' -> remove quote at start and/or end -> remove whitespace

This PR swaps the order to:

split on ',' -> remove whitespace -> remove quote at start and/or end

This fixes the array spacing issue without any major refactor to removeQuotesFromString

Video of built app running with the fixed validation:

testContract.mp4

closes #616

  • npm run format
  • npm run lint

@Snarling Snarling merged commit 0da9d9d into bitburner-official:dev Jan 2, 2024
7 checks passed
G4mingJon4s pushed a commit to G4mingJon4s/bitburner-src that referenced this pull request Mar 23, 2024
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.

Sanitize Parentheses coding contract appears to reject answers with spaces inbetween array string elements
2 participants