Use HTML-compliant encoding for angular http parser

https://github.com/angular/angular/issues/11058
pull/6263/head
Oliver Günther 7 years ago
parent e3b5dd2d68
commit 52e13f1c68
No known key found for this signature in database
GPG Key ID: 88872239EB414F99
  1. 11
      frontend/app/components/wp-query/url-params-helper.ts
  2. 1
      frontend/app/modules/hal/resources/query-operator-resource.ts
  3. 3
      frontend/app/modules/hal/services/hal-resource.service.ts
  4. 50
      frontend/app/modules/hal/services/url-params-encoder.ts

@ -33,6 +33,7 @@ import {Injectable} from '@angular/core';
import {PaginationService} from 'core-components/table-pagination/pagination-service';
import {downgradeInjectable} from '@angular/upgrade/static';
import {opServicesModule} from 'core-app/angular-modules';
import {QueryFilterInstanceResource} from 'core-app/modules/hal/resources/query-filter-instance-resource';
@Injectable()
export class UrlParamsHelperService {
@ -237,7 +238,7 @@ export class UrlParamsHelperService {
}
private buildV3GetFiltersFromQueryResoure(query:QueryResource) {
let filters = query.filters.map((filter:any) => {
let filters = query.filters.map((filter:QueryFilterInstanceResource) => {
let id = this.buildV3GetFilterIdFromFilter(filter);
let operator = this.buildV3GetOperatorIdFromFilter(filter);
let values = this.buildV3GetValuesFromFilter(filter);
@ -251,13 +252,13 @@ export class UrlParamsHelperService {
return JSON.stringify(filters);
}
private buildV3GetFilterIdFromFilter(filter:any) {
private buildV3GetFilterIdFromFilter(filter:QueryFilterInstanceResource) {
let href = filter.filter ? filter.filter.$href : filter._links.filter.href;
return this.idFromHref(href);
}
private buildV3GetOperatorIdFromFilter(filter:any) {
private buildV3GetOperatorIdFromFilter(filter:QueryFilterInstanceResource) {
if (filter.operator) {
return filter.operator.id;
} else {
@ -267,9 +268,9 @@ export class UrlParamsHelperService {
}
}
private buildV3GetValuesFromFilter(filter:any) {
private buildV3GetValuesFromFilter(filter:QueryFilterInstanceResource) {
if (filter.values) {
return _.map(filter.values, (v) => this.queryFilterValueToParam(v));
return _.map(filter.values, (v:any) => this.queryFilterValueToParam(v));
} else {
return _.map(filter._links.values, (v:any) => this.idFromHref(v.href));
}

@ -43,6 +43,7 @@ export class QueryOperatorResource extends HalResource {
return '';
}
public set id(val:string) {
this.$source.id = val;
}

@ -35,6 +35,7 @@ import {CollectionResource} from 'core-app/modules/hal/resources/collection-reso
import {HalLink, HalLinkInterface} from 'core-app/modules/hal/hal-link/hal-link';
import {ErrorObservable} from 'rxjs/observable/ErrorObservable';
import {initializeHalProperties} from 'core-app/modules/hal/helpers/hal-resource-builder';
import {URLParamsEncoder} from 'core-app/modules/hal/services/url-params-encoder';
export interface HalResourceFactoryConfigInterface {
cls?:any;
@ -112,7 +113,7 @@ export class HalResourceService {
public get<T extends HalResource>(href:string, params?:any, headers?:any):Observable<T> {
const config:HTTPClientOptions = {
headers: headers,
params: new HttpParams({ fromObject: params }),
params: new HttpParams({ encoder: new URLParamsEncoder(), fromObject: params }),
withCredentials: true,
responseType: 'json'
}

@ -0,0 +1,50 @@
//-- copyright
// OpenProject is a project management system.
// Copyright (C) 2012-2015 the OpenProject Foundation (OPF)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License version 3.
//
// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
// Copyright (C) 2006-2013 Jean-Philippe Lang
// Copyright (C) 2010-2013 the ChiliProject Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
//
// See doc/COPYRIGHT.rdoc for more details.
//++
import {HttpParameterCodec} from '@angular/common/http';
export class URLParamsEncoder implements HttpParameterCodec {
encodeKey(key:string):string {
return encodeURIComponent(key);
}
encodeValue(value:string):string {
return encodeURIComponent(value);
}
decodeKey(key:string):string {
return decodeURIComponent(key);
}
decodeValue(value:string):string {
return decodeURIComponent(value);
}
}
Loading…
Cancel
Save