Skip to content

Commit

Permalink
fix handling of invalid opcode
Browse files Browse the repository at this point in the history
When we split the string by '_', the resulting parts could be empty strings if the opcode is something like `nrelop_nrel-commute_`, or `nrelop__user1`. We should throw an 'invalid opcode' error in this case
  • Loading branch information
JGreenlee committed Dec 15, 2023
1 parent 9bc5cd6 commit 63732f0
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions www/js/config/dynamicConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,9 @@ async function fetchConfig(studyLabel: string, alreadyTriedLocal?: boolean) {
*/
function extractStudyName(token: string): string {
const tokenParts = token.split('_');
if (tokenParts.length < 3) {
// all tokens must have at least nrelop_[study name]_...
if (tokenParts.length < 3 || tokenParts.some((part) => part == '')) {
// all tokens must have at least nrelop_[studyname]_[usercode]
// and neither [studyname] nor [usercode] can be blank
throw new Error(i18next.t('config.not-enough-parts-old-style', { token: token }));
}
if (tokenParts[0] != 'nrelop') {
Expand Down

0 comments on commit 63732f0

Please sign in to comment.