Skip to content

Commit

Permalink
Added negative lookahead to getResourceName regex (#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
JMach1 authored Mar 2, 2023
1 parent e985668 commit a984002
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { NameValuePair } from "./contracts/nameValuePair";

export class Utils {
public static getResourceName(resource: string, fullId: string, resultType: string = "name"): string {
const regexp = new RegExp(`\/${resource}\/(.*)`);
const regexp = new RegExp(`\/${resource}\/(?!${resource})(.*)`); // negative lookahead to escape cases when "resource" is in "fullId" multiple times in a row (e.g. ...apis/operations/operations/foo - https://github.com/Azure/api-management-developer-portal/issues/2112 )
const matches = regexp.exec(fullId);

if (matches && matches.length > 1) {
Expand Down

0 comments on commit a984002

Please sign in to comment.