From 520024a83d5cce337429e25401f8565661d12520 Mon Sep 17 00:00:00 2001 From: Scott Berg <scott.berg@wisc.edu> Date: Fri, 22 Feb 2019 17:58:05 +0000 Subject: [PATCH] Fix Regex check on subject input --- .../course-search/course-search.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/degree-planner/course-search/course-search.component.ts b/src/app/degree-planner/course-search/course-search.component.ts index f2f7202..747f72e 100644 --- a/src/app/degree-planner/course-search/course-search.component.ts +++ b/src/app/degree-planner/course-search/course-search.component.ts @@ -132,14 +132,16 @@ export class CourseSearchComponent implements OnInit, OnDestroy { 'subject', ) as AbstractControl).valueChanges.subscribe(value => { // If the subject value is blank, or if the user is typing "all" - if (new RegExp('^([Aa]?[Ll]{0,2})$').test(value.trim())) { + if (/^(a[l]{0,2})?$/i.test(value.trim())) { this.filteredSubjects = this.subjects; return; } this.filteredSubjects = this.subjects.filter(subject => { - const search = subject.replace(/\s/g, ''); - if (search.toLowerCase().indexOf(value.toLowerCase()) === 0) { + // Make both comparisons lowercase and remove all whitespace + const formattedSubject = subject.replace(/\s/g, '').toLowerCase(); + const formattedValue = value.replace(/\s/g, '').toLowerCase(); + if (formattedSubject.indexOf(formattedValue) === 0) { return true; } return false; -- GitLab