Skip to content

Commit

Permalink
Merge pull request #9 from caleb-flores/fix/safari-issue
Browse files Browse the repository at this point in the history
fix: issue in safari 'Invalid regular expression'
  • Loading branch information
asnunes committed Sep 21, 2021
2 parents 46f0592 + 5507d70 commit 71ae8b9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/infra/usecases/xmldom-to-mathml-elements/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ export class ErrorHandler {
const missingAttribute = errorMessage.split('"')[1];
if (missingAttribute) return xml.replace(this._matchMissingValueForAttribute(missingAttribute), '');

return xml.replace(this._mathGenericMissingValue(), '');
while (this._mathGenericMissingValue().exec(xml)) {
xml = xml.replace(this._mathGenericMissingValue(), '$1$3');
}
return xml;
}

private _matchMissingValueForAttribute(attribute: string): RegExp {
return new RegExp(`(?<=\<.*)(${attribute}=(?!(\"|\')))|(${attribute}(?!(\"|\')))(?=.*\>)`, 'gm');
return new RegExp(`(${attribute}=(?!(\"|\')))|(${attribute}(?!(\"|\')))`, 'gm');
}

private _mathGenericMissingValue(): RegExp {
return /(?<=\<.*)(\w+=(?!(\"|\')))/gm;
return /(\<.* )(\w+=(?!\"|\'))(.*\>)/gm;
}

private _isMissingAttributeValueError(errorMessage: string): boolean {
Expand Down

0 comments on commit 71ae8b9

Please sign in to comment.