javascript-obfuscator icon indicating copy to clipboard operation
javascript-obfuscator copied to clipboard

Negative reservedNames option doesnt work

Open lecatos opened this issue 9 months ago • 3 comments

Option for reservedNames when renameProperty option is on

Expected Behavior

reservedNames = ["^renameME"] reserved all names except "renameME"

Current Behavior

mangles every names except "renameME"

Steps to Reproduce

  1. reservedNames = ["^renameME"]
  2. Run obfuscation

JavaScript Obfuscator Edition

  • JavaScript Obfuscator Open Source

Your Environment

  • Obfuscator version used:
  • Node version used: v24.13.0

Stack trace

none

Minimal working example that will help to reproduce issue

var JavaScriptObfuscator = require("javascript-obfuscator"); let opt1 = { target: "node", compact: false, stringArray: false, renameProperties: true, renamePropertiesMode: "safe", reservedNames: ["^renameMeOnly"], }

let code = "(function(){function pleasedontrename (){}; function renameMeOnly(){}})"

console.log(JavaScriptObfuscator.obfuscate(code, opt1).getObfuscatedCode());

lecatos avatar Feb 08 '26 07:02 lecatos

Hi, the reservedNames option accepts a regexp string, so the ^ character means the start of a new line, not a negative pattern.

sanex3339 avatar Mar 22 '26 05:03 sanex3339

There's though a different issue that causes infinity loop when a proper negative pattern like ^(?!renameMeOnly$) matches all identifier names. I'll fix it

sanex3339 avatar Mar 22 '26 05:03 sanex3339

Will be released in 5.4.0 later today

sanex3339 avatar Mar 22 '26 07:03 sanex3339