free-be-account 0.0.27 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +25 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1041,10 +1041,33 @@ module.exports = (app) => ({
1041
1041
  const uuid = uuidv1();
1042
1042
 
1043
1043
  res.app.cache.put(`captcha_${uuid}`, captcha.text, m.config.captcha.cache || 300000);
1044
- const matches = captcha.data.match(/d="([^"]*)"/g);
1044
+
1045
+ const pathAndStrokeList = [];
1046
+ // 1. 先把每个 <path .../> 整体拎出来
1047
+ const pathRE = /<path\b[^>]*\/>/gi;
1048
+
1049
+ // 2. 对每个标签再抽属性(顺序无关,可缺)
1050
+ const attrRE = /\b(d|stroke|fill)=["']([^"']*)["']/gi;
1051
+
1052
+ let pathMatch;
1053
+
1054
+ while ((pathMatch = pathRE.exec(captcha.data)) !== null) {
1055
+ const obj = { p: undefined, s: undefined, f: undefined };
1056
+ let attrMatch;
1057
+ attrRE.lastIndex = 0; // 重置内层正则
1058
+ while ((attrMatch = attrRE.exec(pathMatch[0])) !== null) {
1059
+ const [, key, val] = attrMatch;
1060
+ if (key === 'd') obj.p = val;
1061
+ if (key === 'stroke') obj.s = val;
1062
+ if (key === 'fill') obj.f = val;
1063
+ }
1064
+
1065
+ pathAndStrokeList.push(obj);
1066
+ }
1045
1067
 
1046
1068
  res.endWithData({
1047
- captcha: matches.map((m) => m.replace('d="', '').replace('"', '')),
1069
+ captcha: pathAndStrokeList,
1070
+ f: m.config.captcha.options.background,
1048
1071
  id: uuid,
1049
1072
  });
1050
1073
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "free-be-account",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "main": "index.js",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {