Skip to content

Commit a8e8917

Browse files
committed
Escaping ':' in search queries, except if advanced=true
Following up on the issue DSpace/DSpace#9670 - here is a first proposal. Per default, this sets the 'advanced' flag to false and will escape ':' characters in the search string. Only with 'advanced = true' is the search string passed as-is. TODO: - add tests - make sure this looks good
1 parent f95596b commit a8e8917

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

src/app/shared/search-form/search-form.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<input type="text" [(ngModel)]="query" name="query" class="form-control"
1212
[attr.aria-label]="searchPlaceholder" [attr.data-test]="'search-box' | dsBrowserOnly"
1313
[placeholder]="searchPlaceholder">
14+
<input type="checkbox" [(ngModel)]="advanced" [attr.name]="{{ ('search.form.advanced' | translate ) }}" checked />
1415
<button type="submit" class="search-button btn btn-{{brandColor}}" [attr.data-test]="'search-button' | dsBrowserOnly"><i class="fas fa-search"></i> {{ ('search.form.search' | translate) }}</button>
1516
</div>
1617
</div>

src/app/shared/search-form/search-form.component.ts

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ export class SearchFormComponent implements OnChanges {
4848
*/
4949
@Input() query: string;
5050

51+
/**
52+
* True to pass the search query without esacping of special characters.
53+
*/
54+
@Input() advanced: boolean;
55+
5156
/**
5257
* True when the search component should show results on the current page
5358
*/

src/app/shared/search/models/search-options.model.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ export class SearchOptions {
1818
dsoTypes?: DSpaceObjectType[];
1919
filters?: SearchFilter[];
2020
fixedFilter?: string;
21+
advanced?: boolean;
2122

2223
constructor(
2324
options: {
2425
configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[],
25-
fixedFilter?: string
26+
fixedFilter?: string, advanced?: boolean
2627
},
2728
) {
2829
this.configuration = options.configuration;
@@ -31,6 +32,7 @@ export class SearchOptions {
3132
this.dsoTypes = options.dsoTypes;
3233
this.filters = options.filters;
3334
this.fixedFilter = options.fixedFilter;
35+
this.advanced = options.advanced;
3436
}
3537

3638
/**
@@ -47,6 +49,9 @@ export class SearchOptions {
4749
args.push(this.encodedFixedFilter);
4850
}
4951
if (isNotEmpty(this.query)) {
52+
if (!this.advanced){
53+
this.query.replace(":", "\:");
54+
}
5055
args.push(`query=${encodeURIComponent(this.query)}`);
5156
}
5257
if (isNotEmpty(this.scope)) {

src/app/shared/search/search.component.ts

+7
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import { SelectionConfig } from './search-results/search-results.component';
8282
import { ThemedSearchResultsComponent } from './search-results/themed-search-results.component';
8383
import { ThemedSearchSidebarComponent } from './search-sidebar/themed-search-sidebar.component';
8484
import { SearchConfigurationOption } from './search-switch-configuration/search-configuration-option.model';
85+
import { compileOpaqueAsyncClassMetadata } from '@angular/compiler';
8586

8687
@Component({
8788
selector: 'ds-base-search',
@@ -227,6 +228,11 @@ export class SearchComponent implements OnDestroy, OnInit {
227228
*/
228229
@Input() query: string;
229230

231+
/**
232+
* True to pass the query as-is without escaping of special characters.
233+
*/
234+
@Input() advanced = false;
235+
230236
/**
231237
* The fallback scope when no scope is defined in the url, if this is also undefined no scope will be set
232238
*/
@@ -427,6 +433,7 @@ export class SearchComponent implements OnDestroy, OnInit {
427433
});
428434
if (combinedOptions.query === '') {
429435
combinedOptions.query = this.query;
436+
combinedOptions.advanced = this.advanced;
430437
}
431438
if (isEmpty(combinedOptions.scope)) {
432439
combinedOptions.scope = scope;

src/assets/i18n/en.json5

+2
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,8 @@
47374737

47384738
"search.form.search": "Search",
47394739

4740+
"search.form.search": "Advanced",
4741+
47404742
"search.form.search_dspace": "All repository",
47414743

47424744
"search.form.scope.all": "All of DSpace",

0 commit comments

Comments
 (0)