Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with extra ampersand being included right after question mark. #34

Merged
merged 1 commit into from Apr 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 4 additions & 7 deletions src/adapter-ajax-httpclient.ts
@@ -1,6 +1,7 @@
import { HttpClient, HttpErrorResponse, HttpEvent, HttpHeaders, HttpRequest, HttpResponse } from "@angular/common/http";
import { AjaxConfig, config, core, HttpResponse as BreezeHttpResponse, BreezeConfig } from "breeze-client";
import { filter, map } from "rxjs/operators";
import { appendQueryStringParameters } from "./adapter-core";

export class AjaxHttpClientAdapter {
static adapterName = 'httpclient';
Expand Down Expand Up @@ -36,13 +37,9 @@ export class AjaxHttpClientAdapter {
throw new Error(this.name + ' does not support JSONP (crossDomain) requests');
}

let url = config.url;
if (!core.isEmpty(config.params)) {
// Hack: Not sure how Angular handles writing 'search' parameters to the url.
// so this approach takes over the url param writing completely.
let delim = (url.indexOf('?') >= 0) ? '&' : '?';
url = url + delim + encodeParams(config.params);
}
let parameters = core.isEmpty(config.params) ? null : encodeParams(config.params);

const url = appendQueryStringParameters(parameters, config.url);

let headers = new HttpHeaders(config.headers || {});
if (!headers.has('Content-Type')) {
Expand Down
17 changes: 17 additions & 0 deletions src/adapter-core.ts
@@ -0,0 +1,17 @@
export function appendQueryStringParameters(parameters: string, url: string){
if(!parameters) return url;

let separator: string;

if(url.endsWith("?")){
separator = "";
}
else if(url.includes("?")){
separator = "&";
}
else{
separator = "?";
}

return url + separator + parameters;
}
5 changes: 3 additions & 2 deletions src/adapter-uri-builder-odata.ts
@@ -1,4 +1,5 @@
import * as breeze from 'breeze-client';
import { appendQueryStringParameters } from "./adapter-core";

export class UriBuilderODataAdapter implements breeze.UriBuilderAdapter {

Expand Down Expand Up @@ -44,8 +45,8 @@ export class UriBuilderODataAdapter implements breeze.UriBuilderAdapter {
}

let qoText = toQueryOptionsString(queryOptions as breeze.QueryOptions);
let sep = entityQuery.resourceName.includes("?") ? "&" : "?";
return entityQuery.resourceName + sep + qoText;

return appendQueryStringParameters(qoText, entityQuery.resourceName);

// private methods to this func.

Expand Down