Skip to content

Commit 2869aea

Browse files
author
Michael Wunderlich
committed
validate rules name
1 parent 423a3b1 commit 2869aea

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/main/java/scorekeep/MoveFactory.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ public Move newMove(String sessionId, String gameId, String userId, String moveT
4444
if (newTurn.size() != 1) {
4545
newTurn.remove(userId);
4646
}
47+
String rulesName = game.getRules();
48+
if ( !rulesName.matches("[a-zA-Z]{1,16}") ) {
49+
throw new RulesException(rulesName);
50+
}
4751
try {
48-
Class<?> rules = Class.forName("scorekeep." + game.getRules());
52+
Class<?> rules = Class.forName("scorekeep." + rulesName);
4953
Method moveMethod = rules.getMethod("move", String.class, String.class);
5054
newStateText = (String) moveMethod.invoke(null, oldState.getState(), moveText);
51-
} catch ( ClassNotFoundException e ) { throw new RulesException(game.getRules()); }
52-
catch ( NoSuchMethodException f ) { throw new RulesException(game.getRules()); }
53-
catch ( IllegalAccessException g ) { throw new RulesException(game.getRules()); }
54-
catch ( InvocationTargetException h ) { throw new RulesException(game.getRules()); }
55+
} catch ( ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RulesException(rulesName); }
5556
// save new game state
5657
State newState = new State(stateId, sessionId, gameId, newStateText, newTurn);
5758
// register state and move id to game

0 commit comments

Comments
 (0)