TheNorthMemory/wechatpay-axios-plugin

正则匹配有个问题,铁子

sdz123 opened this issue · 2 comments

比如下面这串代码:
wxpay.v3.transfer.batches.outBatchNo['1234567899900011'].details.outDetailNo['x16683940311151111X'].get();
后面的outDetailNo参数最后一位X会被正则处理成 ‘-x’;

segments 受如下处理过程约束:

/**
* Normalize the `str` by the rules: `PascalCase` -> `camelCase` & `camelCase` -> `camel-case` & `$dynamic$` -> `{dynamic}`
* @param {string} str - The string waiting for normalization
* @returns {string} - The transformed string
*/
static normalize(str) {
return (str || '')
// PascalCase` to `camelCase`
.replace(/^[A-Z]/, (w) => w.toLowerCase())
// `camelCase` to `camel-case`
.replace(/[A-Z]/g, (w) => `-${w.toLowerCase()}`)
// `$dynamic_variable$` to `{dynamic_variable}`
.replace(/^(\$|_)(.*)\1$/, '{$2}');
}

你的代码需要微调成:

wxpay.v3.transfer.batches.outBatchNo.$out_batch_no$.details.outDetailNo._out_detail_no_.get({
  out_batch_no: '1234567899900011',
  out_detail_no: 'x16683940311151111X',
})

segments 受如下处理过程约束:

/**
* Normalize the `str` by the rules: `PascalCase` -> `camelCase` & `camelCase` -> `camel-case` & `$dynamic$` -> `{dynamic}`
* @param {string} str - The string waiting for normalization
* @returns {string} - The transformed string
*/
static normalize(str) {
return (str || '')
// PascalCase` to `camelCase`
.replace(/^[A-Z]/, (w) => w.toLowerCase())
// `camelCase` to `camel-case`
.replace(/[A-Z]/g, (w) => `-${w.toLowerCase()}`)
// `$dynamic_variable$` to `{dynamic_variable}`
.replace(/^(\$|_)(.*)\1$/, '{$2}');
}

你的代码需要微调成:

wxpay.v3.transfer.batches.outBatchNo.$out_batch_no$.details.outDetailNo._out_detail_no_.get({
  out_batch_no: '1234567899900011',
  out_detail_no: 'x16683940311151111X',
})

感谢您的回复!