Skip to content

Commit 58b0bcb

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 bca7828 commit 58b0bcb

5 files changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ export class SearchOptions {
1919
dsoTypes?: DSpaceObjectType[];
2020
filters?: SearchFilter[];
2121
fixedFilter?: string;
22+
advanced?: boolean;
2223

2324
constructor(
2425
options: {
2526
configuration?: string, scope?: string, query?: string, dsoTypes?: DSpaceObjectType[], filters?: SearchFilter[],
26-
fixedFilter?: string
27+
fixedFilter?: string, advanced?: boolean
2728
},
2829
) {
2930
this.configuration = options.configuration;
@@ -32,6 +33,7 @@ export class SearchOptions {
3233
this.dsoTypes = options.dsoTypes;
3334
this.filters = options.filters;
3435
this.fixedFilter = options.fixedFilter;
36+
this.advanced = options.advanced;
3537
}
3638

3739
/**
@@ -48,6 +50,9 @@ export class SearchOptions {
4850
args.push(this.encodedFixedFilter);
4951
}
5052
if (isNotEmpty(this.query)) {
53+
if (!this.advanced){
54+
this.query.replace(':', '\:');
55+
}
5156
args.push(`query=${encodeURIComponent(this.query)}`);
5257
}
5358
if (isNotEmpty(this.scope)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<input type="text" [(ngModel)]="query" name="query" class="form-control"
1313
[attr.aria-label]="searchPlaceholder" [attr.data-test]="'search-box' | dsBrowserOnly"
1414
[placeholder]="searchPlaceholder" tabindex="0">
15+
<input type="checkbox" [(ngModel)]="advanced" [attr.name]="{{ ('search.form.advanced' | translate ) }}" checked />
1516
<button type="submit" class="search-button btn btn-{{brandColor}}" [attr.data-test]="'search-button' | dsBrowserOnly" role="button" tabindex="0"><i class="fas fa-search"></i> {{ ('search.form.search' | translate) }}</button>
1617
</div>
1718
</div>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export class SearchFormComponent implements OnChanges {
5353
*/
5454
@Input() query: string;
5555

56+
/**
57+
* True to pass the search query without esacping of special characters.
58+
*/
59+
@Input() advanced: boolean;
60+
5661
/**
5762
* True when the search component should show results on the current page
5863
*/

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ export class SearchComponent implements OnDestroy, OnInit {
228228
*/
229229
@Input() query: string;
230230

231+
/**
232+
* True to pass the query as-is without escaping of special characters.
233+
*/
234+
@Input() advanced = false;
235+
231236
/**
232237
* The fallback scope when no scope is defined in the url, if this is also undefined no scope will be set
233238
*/
@@ -428,6 +433,7 @@ export class SearchComponent implements OnDestroy, OnInit {
428433
});
429434
if (combinedOptions.query === '') {
430435
combinedOptions.query = this.query;
436+
combinedOptions.advanced = this.advanced;
431437
}
432438
if (isEmpty(combinedOptions.scope)) {
433439
combinedOptions.scope = scope;

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4940,6 +4940,8 @@
49404940

49414941
"search.form.search": "Search",
49424942

4943+
"search.form.search": "Advanced",
4944+
49434945
"search.form.search_dspace": "All repository",
49444946

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

0 commit comments

Comments
 (0)