Skip to content

Commit e171ec2

Browse files
committed
GUACAMOLE-1020: Handle differences in Sunday processing for Java and JavaScript.
1 parent b1acb91 commit e171ec2

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

extensions/guacamole-auth-restrict/src/main/java/org/apache/guacamole/calendar/TimeRestrictionParser.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class TimeRestrictionParser {
4949
* </ul>
5050
*/
5151
private static final Pattern RESTRICTION_REGEX =
52-
Pattern.compile("(?:^|;)+([1-7*])(?::((?:[01][0-9]|2[0-3])[0-5][0-9])\\-((?:[01][0-9]|2[0-3])[0-5][0-9]))+");
52+
Pattern.compile("(?:^|;)+([0-7*])(?::((?:[01][0-9]|2[0-3])[0-5][0-9])\\-((?:[01][0-9]|2[0-3])[0-5][0-9]))+");
5353

5454
/**
5555
* The RegEx group that contains the start day-of-week of the restriction.
@@ -136,7 +136,14 @@ public static List<DailyRestriction> parseString(String restrictionString) {
136136

137137
// A specific day of the week.
138138
default:
139-
restrictions.add(new DailyRestriction(DayOfWeek.of(Integer.parseInt(dayString)), startTime, endTime));
139+
int dayInt = Integer.parseInt(dayString);
140+
141+
// While JavaScript sees Sunday as "0" and "7", DayOfWeek
142+
// does not, so we'll convert it to "7" in order to process it.
143+
if (dayInt == 0)
144+
dayInt = 7;
145+
146+
restrictions.add(new DailyRestriction(DayOfWeek.of(dayInt), startTime, endTime));
140147

141148
}
142149

extensions/guacamole-auth-restrict/src/main/resources/controllers/timeRestrictionFieldController.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ angular.module('guacRestrict').controller('timeRestrictionFieldController', ['$s
5858
* twice - once for the 0-index and once for the 7 index.
5959
*/
6060
$scope.weekDays = [
61-
{ id : '0', day : 'Sunday' },
6261
{ id : '1', day : 'Monday' },
6362
{ id : '2', day : 'Tuesday' },
6463
{ id : '3', day : 'Wednesday' },
@@ -132,8 +131,16 @@ angular.module('guacRestrict').controller('timeRestrictionFieldController', ['$s
132131
if (restrictionRegex.test(restrArray[i])) {
133132
var currArray = restrArray[i].match(restrictionRegex);
134133
let entry = new TimeRestrictionEntry();
135-
entry.startTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[2].slice(0,2)), parseInt(currArray[2].slice(2))));
136-
entry.endTime = new Date(Date.UTC(templateDate.getFullYear(), templateDate.getMonth(), templateDate.getDate(), parseInt(currArray[3].slice(0,2)), parseInt(currArray[3].slice(2))));
134+
entry.startTime = new Date(Date.UTC(templateDate.getFullYear(),
135+
templateDate.getMonth(),
136+
templateDate.getDate(),
137+
parseInt(currArray[2].slice(0,2)),
138+
parseInt(currArray[2].slice(2))));
139+
entry.endTime = new Date(Date.UTC(templateDate.getFullYear(),
140+
templateDate.getMonth(),
141+
templateDate.getDate(),
142+
parseInt(currArray[3].slice(0,2)),
143+
parseInt(currArray[3].slice(2))));
137144
var origDay = currArray[1];
138145

139146
if (currArray[1] === '*')

0 commit comments

Comments
 (0)