Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix show-text-modal-directive.js(#4131) #4183

Merged
merged 4 commits into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Apollo 2.0.0
* [Fix the issue that property placeholder doesn't work for dubbo reference beans](https://github.com/apolloconfig/apollo/pull/4175)
* [Fix the NPE occurred when using EnableApolloConfig with Spring 3.1.1](https://github.com/apolloconfig/apollo/pull/4180)
* [Bump guava from 29.0 to 31.0.1](https://github.com/apolloconfig/apollo/pull/4182)
* [fix the json number display issue when it's longer than 16](https://github.com/apolloconfig/apollo/pull/4183)

------------------
All issues and pull requests are [here](https://github.com/ctripcorp/apollo/milestone/8?closed=1)
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,42 @@ directive_module.directive('showtextmodal', showTextModalDirective)
return;
}

const numberRegex = /\d{16,}/g;
const splitRegex = /"\d\d+"/;
const numberRegex = /"\|+\d+\|+"/g;
const splitRegex = /"\|+\d+\|+"/;
const splitArray = text.split(splitRegex);
const matchResult = text.match(numberRegex);

if (!matchResult) {
const borderRegex = /"\|\d+\|"/;
if (!matchResult || 0 === splitArray.length) {
return text;
} else {
Object.keys(matchResult).forEach(function (key) {
if (matchResult[key].includes('"\|')) {
if (borderRegex.test(matchResult[key])) {
matchResult[key] = matchResult[key].replaceAll('"\|', '');
matchResult[key] = matchResult[key].replaceAll('|\"', '');
} else {
matchResult[key] = matchResult[key].replaceAll('"\|', '"');
matchResult[key] = matchResult[key].replaceAll('|\"', '"');
}
}
});
}

let resultStr = '';
let index = 0;

const isJsonText = resultStr => {
try {
return typeof JSON.parse(resultStr) === "object";
} catch (e) {
return false;
}
};

Object.keys(splitArray).forEach(function (key) {
resultStr = resultStr.concat(splitArray[key]);
if (typeof(matchResult[index]) !== "undefined") {
if (typeof(matchResult[index]) !== "undefined"
&& !isJsonText(resultStr)) {
resultStr = resultStr.concat(matchResult[index++])
}
})
Expand Down Expand Up @@ -74,18 +95,21 @@ function showTextModalDirective(AppUtil) {
}

function parseBigInt(str) {
if (/\d{16,}/.test(str)) {
if (/\d+/.test(str)) {
let replaceMap = [];
let n = 0;
str = str.replace(/"(\\?[\s\S])*?"/g, function (match) {
if (/\d{16,}/.test(match)) {
str = str.replace(/"\|+\d+\|+"/g, function (match) {
return match.replace('"\|', '"\||').replace('|"', '||"');
})
.replace(/"(\\?[\s\S])*?"/g, function (match) {
if (/\d+/.test(match)) {
replaceMap.push(match);
return '"""';
}
return match;
}).replace(/[+\-\d.eE]{16,}/g, function (match) {
if (/^\d{16,}$/.test(match)) {
return '"' + match + '"';
}).replace(/[+\-\d.eE]+/g, function (match) {
if (/^\d+$/.test(match)) {
return '"|' + match + '|"';
}
return match;
}).replace(/"""/g, function () {
Expand Down