jo3-l / obscenity

Robust, extensible profanity filter for NodeJS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bug: Using .addPhrase with Angular script optimization causes error that prevents Angular from bootstrapping

cody-01 opened this issue · comments

Expected behavior

I expected .addPhrase to include my added obscene term and build properly.

Actual behavior

Using .addPhrase in an Angular component and optimization: scripts = true in angular.json's build config causes the following error:
Cannot read properties of undefined (reading 'Literal');

This error prevented Angular from bootstrapping

Minimal reproducible example

Add this block to angular.json. "scripts: true" being the one that creates the issue. Seems like something to do with minification.

"optimization": { "styles": { "minify": true, "inlineCritical": true }, "scripts": true, "fonts": true },

Import the package to a component.
import { DataSet, RegExpMatcher, englishDataset, englishRecommendedTransformers, pattern } from 'obscenity';

In ngOnInit, add custom phrases to the DataSet

    const customDataSet = new DataSet()
      .addAll(englishDataset)
      .addPhrase((phrase) => phrase.addPattern(pattern`|damn|`))
      .addPhrase((phrase) => phrase.addPattern(pattern`|hell|`).addWhitelistedTerm('hello'));

    this.matcher = new RegExpMatcher({
      ...customDataSet.build(),
      ...englishRecommendedTransformers,
    });

...

Steps to reproduce

NOTE: This works fine in v0.1.4

  • Configure you Angular project to optimize scripts (minify) in the angular.json file
  • Using an Angular component...
  • Import englishDataset and DataSet
  • In ngOnInit, create a custom dataset that starts with the englishDataset
  • Add custom phrases to that DataSet using addPhrase => addPattern
  • Notice error: Cannot read properties of undefined (reading 'Literal');

Additional context

No response

Node.js version

v18.12.1

Obscenity version

v0.2.0

Priority

  • Low
  • Medium
  • High

Terms

  • I agree to follow the project's Code of Conduct.
  • I have searched existing issues for similar reports.

Please provide a MRE and steps to reproduce.

Edit: Thanks for the repro, I will try to take a look at this when I can, though this is almost certainly an upstream issue as opposed to a bug in the Obscenity package.