Fixed issue internal source defect

Signed-off-by: xdmal <maxiaodong16@huawei.com>
This commit is contained in:
xdmal
2022-03-21 15:41:57 +08:00
parent 597ec805eb
commit 8501721f55
12 changed files with 93 additions and 106 deletions
-4
View File
@@ -414,8 +414,6 @@ var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length*2);
var bufView = new Uint8Array(arrayBuffer);
@@ -432,8 +430,6 @@ var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <todo>Work</todo>' +
' <todo>Play</todo>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length*2);
var bufView = new Uint8Array(arrayBuffer);
-4
View File
@@ -413,8 +413,6 @@ var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <title>Work</title>' +
' <title>Play</title>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length*2);
var bufView = new Uint8Array(arrayBuffer);
@@ -431,8 +429,6 @@ var strXml =
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
' <title>Happy</title>' +
' <title>Work</title>' +
' <title>Play</title>' +
'</note>';
var arrayBuffer = new ArrayBuffer(strXml.length*2);
var bufView = new Uint8Array(arrayBuffer);
+4 -4
View File
@@ -124,10 +124,10 @@ namespace OHOS::Xml {
}
if (curNode->type == xmlElementType::XML_COMMENT_NODE && !options_.ignoreComment) {
SetKeyValue(elementsObject, options_.type, GetNodeType(curNode->type));
char *curContent = reinterpret_cast<char*>(xmlNodeGetContent(curNode));
if (curContent != nullptr) {
SetKeyValue(elementsObject, options_.comment, curContent);
xmlFree(reinterpret_cast<void*>(curContent));
char *curContent_ = reinterpret_cast<char*>(xmlNodeGetContent(curNode));
if (curContent_ != nullptr) {
SetKeyValue(elementsObject, options_.comment, curContent_);
xmlFree(reinterpret_cast<void*>(curContent_));
}
prevObj_.push_back(elementsObject);
}
+1 -1
View File
@@ -32,7 +32,7 @@ namespace OHOS::Xml {
auto objectInfo = new ConvertXml(env);
napi_wrap(
env, thisVar, objectInfo,
[](napi_env env, void *data, void *hint) {
[](napi_env env_, void *data, void *hint) {
auto obj = (ConvertXml*)data;
if (obj != nullptr) {
delete obj;
+11 -11
View File
@@ -26,7 +26,7 @@ interface ConvertXML {
ConvertXml : NativeConvertXml;
}
declare function requireInternal(s : string) : ConvertXML;
const convertXml = requireInternal("ConvertXML");
const convertXml = requireInternal('ConvertXML');
class ConvertXML {
convertxmlclass : NativeConvertXml;
@@ -37,19 +37,19 @@ class ConvertXML {
strXml = DealXml(strXml);
let converted = this.convertxmlclass.convert(strXml, options);
let strEnd : string = '';
if (converted.hasOwnProperty("spaces")) {
if (converted.hasOwnProperty('spaces')) {
let space : string | number | undefined = converted.spaces;
delete converted.spaces;
strEnd = JSON.stringify(converted, null, space);
}
let idx : number = 0;
while ((idx = strEnd.indexOf('\\t')) != -1) {
while ((idx = strEnd.indexOf('\\t')) !== -1) {
strEnd = strEnd.substring(0, idx) + '\t' + strEnd.substring(idx + 2);
}
while ((idx = strEnd.indexOf('\\n')) != -1) {
while ((idx = strEnd.indexOf('\\n')) !== -1) {
strEnd = strEnd.substring(0, idx) + '\n' + strEnd.substring(idx + 2);
}
while ((idx = strEnd.indexOf('\\')) != -1) {
while ((idx = strEnd.indexOf('\\')) !== -1) {
strEnd = strEnd.substring(0, idx) + '' + strEnd.substring(idx + 1);
}
return strEnd;
@@ -63,16 +63,16 @@ function DealXml(strXml : string)
let idxThir : number = 0;
let idxCData : number = 0;
let idxCDataSec : number = 0;
while ((idx = strXml.indexOf(']]><![CDATA')) != -1) {
while ((idx = strXml.indexOf(']]><![CDATA')) !== -1) {
strXml = strXml.substring(0, idx + 3) + ' ' + strXml.substring(idx + 3);
}
while ((idx = strXml.indexOf('>', idxSec)) != -1) {
while ((idx = strXml.indexOf('>', idxSec)) !== -1) {
idxThir = strXml.indexOf('<', idx);
strXml = DealPriorReplace(strXml, idx, idxThir);
if (strXml.indexOf('<', idx) != -1) {
if (strXml.indexOf('<', idx) !== -1) {
idxCData = strXml.indexOf('<![CDATA', idxCDataSec);
idxSec = strXml.indexOf('<', idx);
if (idxSec == idxCData) {
if (idxSec === idxCData) {
idxSec = strXml.indexOf(']]>', idxCData);
strXml = DealLaterReplace(strXml, idx, idxThir);
idxCDataSec = idxSec;
@@ -90,7 +90,7 @@ function DealPriorReplace(strXml : string, idx : number, idxThir : number)
let i : number = idx + 1;
for (; i < idxThir ; i++) {
let cXml : string = strXml.charAt(i);
if (cXml != '\n' && cXml != '\v' && cXml != '\t' && cXml != ' ')
if (cXml !== '\n' && cXml !== '\v' && cXml !== '\t' && cXml !== ' ')
{
break;
}
@@ -98,7 +98,7 @@ function DealPriorReplace(strXml : string, idx : number, idxThir : number)
let j : number = idx + 1;
for (; j < strXml.indexOf('<', idx) ; j++) {
let cXml : string = strXml.charAt(j);
if (i != idxThir) {
if (i !== idxThir) {
switch (cXml) {
case '\n':
strXml = strXml.substring(0, j) + '\\n' + strXml.substring(j + 1);
+1 -1
View File
@@ -56,7 +56,7 @@ namespace OHOS::Uri {
napi_throw_error(env, nullptr, "parameter type is error");
}
NAPI_CALL(env, napi_wrap(env, thisVar, object,
[](napi_env env, void *data, void *hint) {
[](napi_env env_, void *data, void *hint) {
auto obj = reinterpret_cast<Uri*>(data);
if (obj != nullptr) {
delete obj;
+4 -4
View File
@@ -33,13 +33,13 @@ interface UriInterface{
Uri : NativeUri;
}
declare function requireInternal(s : string) : UriInterface;
const uri = requireInternal("uri");
const uri = requireInternal('uri');
class URI {
uricalss : NativeUri
constructor(input : string) {
if (typeof input !== 'string' || input.length === 0) {
throw new Error("input type err");
throw new Error('input type err');
}
this.uricalss = new uri.Uri(input);
let errStr : string = this.uricalss.isFailed;
@@ -104,8 +104,8 @@ class URI {
function toAscllString(uriStr : string) {
if (uriStr.indexOf('[') !== -1) {
let arr : string[] = uriStr.split("[");
let brr : string[] = arr[1].split("]");
let arr : string[] = uriStr.split('[');
let brr : string[] = arr[1].split(']');
arr[1] = '[' + brr[0] + ']';
arr[2] = brr[1];
arr[0] = encodeURI(arr[0]);
+35 -35
View File
@@ -210,9 +210,9 @@ namespace OHOS::Url {
}
if (userAndPasswd.find('@') != std::string::npos) {
while (true) {
size_t i = 0;
if ((i = userAndPasswd.find('@')) != std::string::npos) {
userAndPasswd = userAndPasswd.replace(i, 1, "%40");
size_t pos = 0;
if ((pos = userAndPasswd.find('@')) != std::string::npos) {
userAndPasswd = userAndPasswd.replace(pos, 1, "%40");
} else {
break;
}
@@ -220,9 +220,9 @@ namespace OHOS::Url {
}
if (userAndPasswd.find(':') != std::string::npos) {
size_t i = userAndPasswd.find(':');
std::string user = userAndPasswd.substr(0, i);
std::string keyWord = userAndPasswd.substr(i + 1);
size_t pos_ = userAndPasswd.find(':');
std::string user = userAndPasswd.substr(0, pos_);
std::string keyWord = userAndPasswd.substr(pos_ + 1);
if (!user.empty()) {
username = user;
flags.set(static_cast<size_t>(BitsetStatusFlag::BIT2));
@@ -519,12 +519,12 @@ namespace OHOS::Url {
{
int val = 0;
if (radix == 16) { // 16:hex
if (sscanf_s(num.c_str(), "%x", &val) == 0) {
if (sscanf_s(num.c_str(), "%x", &val) == EOK) {
HILOG_ERROR("sscanf_s is falie");
}
return std::to_string(val);
} else if (radix == 8) { // 8:octal
if (sscanf_s(num.c_str(), "%o", &val) == 0) {
if (sscanf_s(num.c_str(), "%o", &val) == EOK) {
HILOG_ERROR("sscanf_s is falie");
}
return std::to_string(val);
@@ -873,14 +873,14 @@ namespace OHOS::Url {
AnalysisHost(strHost, urlinfo.host, flags, special);
AnalysisPath(strPath, urlinfo.path, flags, special);
} else {
std::string strHost = hostandpath;
AnalyStrHost(strHost, urlinfo, flags);
AnalyHostPath(strHost, flags, urlinfo);
AnalysisHost(strHost, urlinfo.host, flags, special);
std::string strHost_ = hostandpath;
AnalyStrHost(strHost_, urlinfo, flags);
AnalyHostPath(strHost_, flags, urlinfo);
AnalysisHost(strHost_, urlinfo.host, flags, special);
}
} else if (input[1] == '/') {
std::string strPath = input.substr(1);
AnalysisPath(strPath, urlinfo.path, flags, false);
std::string strPath_ = input.substr(1);
AnalysisPath(strPath_, urlinfo.path, flags, false);
} else {
AnalyInfoPath(flags, urlinfo, input);
}
@@ -973,16 +973,16 @@ namespace OHOS::Url {
std::bitset<static_cast<size_t>(BitsetStatusFlag::BIT_STATUS_11)>& flags)
{
if (input.find('#') != std::string::npos) {
size_t i = input.find('#');
std::string fragment = input.substr(i);
size_t pos = input.find('#');
std::string fragment = input.substr(pos);
AnalysisFragment(fragment, urlData.fragment, flags);
input = input.substr(0, i);
input = input.substr(0, pos);
}
if (input.find('?') != std::string::npos) {
size_t i = input.find('?');
std::string query = input.substr(i);
size_t pos_ = input.find('?');
std::string query = input.substr(pos_);
AnalysisQuery(query, urlData.query, flags);
input = input.substr(0, i);
input = input.substr(0, pos_);
}
bool special = (flags.test(static_cast<size_t>(BitsetStatusFlag::BIT1)) ? true : false);
AnalysisPath(input, urlData.path, flags, special);
@@ -1049,16 +1049,16 @@ namespace OHOS::Url {
return;
}
if (input.find('#') != std::string::npos) {
size_t i = input.find('#');
std::string fragment = input.substr(i);
size_t pos = input.find('#');
std::string fragment = input.substr(pos);
AnalysisFragment(fragment, urlData.fragment, flags);
input = input.substr(0, i);
input = input.substr(0, pos);
}
if (input.find('?') != std::string::npos) {
size_t i = input.find('?');
std::string query = input.substr(i);
size_t pos_ = input.find('?');
std::string query = input.substr(pos_);
AnalysisQuery(query, urlData.query, flags);
input = input.substr(0, i);
input = input.substr(0, pos_);
}
std::string str = input.substr(pos);
if (urlData.scheme == "file:") {
@@ -1668,16 +1668,16 @@ namespace OHOS::Url {
std::string firstStrValue = ReviseStr(searchParams[1], reviseChar);
output = firstStrKey + "=" + firstStrValue;
if (lenStr % 2 == 0) { // 2:Divisible by 2
size_t i = 2; // 2:Initial Position
for (; i < lenStr; i += 2) { // 2:Searching for the number and number of keys and values
std::string strKey = ReviseStr(searchParams[i], reviseChar);
std::string strValue = ReviseStr(searchParams[i + 1], reviseChar);
size_t pos = 2; // 2:Initial Position
for (; pos < lenStr; pos += 2) { // 2:Searching for the number and number of keys and values
std::string strKey = ReviseStr(searchParams[pos], reviseChar);
std::string strValue = ReviseStr(searchParams[pos + 1], reviseChar);
output += +"&" + strKey + "=" + strValue;
}
}
napi_value result = nullptr;
napi_create_string_utf8(env, output.c_str(), output.size(), &result);
return result;
napi_value result_ = nullptr;
napi_create_string_utf8(env, output.c_str(), output.size(), &result_);
return result_;
}
void URLSearchParams::HandleIllegalChar(std::wstring& inputStr, std::wstring::const_iterator it)
{
@@ -1728,7 +1728,7 @@ namespace OHOS::Url {
size_t reSize = wcstombs(rePtr, winput.c_str(), 0) + 1;
if (reSize > 0) {
rePtr = new char[reSize];
if (memset_s(rePtr, reSize, 0, reSize) != 0) {
if (memset_s(rePtr, reSize, 0, reSize) != EOK) {
HILOG_ERROR("ToUSVString memset_s failed");
delete[] rePtr;
return reStr;
@@ -1871,7 +1871,7 @@ namespace OHOS::Url {
napi_get_value_string_utf8(env, name, nullptr, 0, &bufferSize);
if (bufferSize > 0) {
buffer = new char[bufferSize + 1];
if (memset_s(buffer, bufferSize + 1, 0, bufferSize + 1) != 0) {
if (memset_s(buffer, bufferSize + 1, 0, bufferSize + 1) != EOK) {
HILOG_ERROR("type memset error");
delete [] buffer;
return nullptr;
+2 -2
View File
@@ -104,7 +104,7 @@ namespace OHOS::Url {
}
napi_wrap(
env, thisVar, object,
[](napi_env env, void *data, void *hint) {
[](napi_env env_, void *data, void *hint) {
auto obj = (URL*)data;
if (obj != nullptr) {
delete obj;
@@ -552,7 +552,7 @@ namespace OHOS::Url {
auto object = new URLSearchParams(env);
napi_wrap(
env, thisVar, object,
[](napi_env env, void *data, void *hint) {
[](napi_env env_, void *data, void *hint) {
auto obj = (URLSearchParams*)data;
if (obj != nullptr) {
delete obj;
+1 -2
View File
@@ -57,8 +57,7 @@ var seachParamsArr : Array<string> = [];
class URLSearchParams {
urlcalss : NativeURLSearchParams;
constructor(input : object | string | Iterable<[]> | null | undefined) {
let out = [];
out = parameterProcessing(input);
let out : string[] = parameterProcessing(input);
this.urlcalss = new UrlInterface.URLSearchParams1();
this.urlcalss.array = out;
}
+17 -22
View File
@@ -195,10 +195,10 @@ namespace OHOS::xml {
elementStack[depth_ * 3 + 1] = ""; // 3: number of args
type = "isEndTag";
out_.append(">");
size_t iLenTemp = out_.length();
if (iLength_ > iPos_ + iLenTemp - 1) {
if (!memcpy_s(pStart_ + iPos_, iLength_ - iPos_, out_.c_str(), iLenTemp)) {
iPos_ += iLenTemp;
size_t iLenTemp_ = out_.length();
if (iLength_ > iPos_ + iLenTemp_ - 1) {
if (!memcpy_s(pStart_ + iPos_, iLength_ - iPos_, out_.c_str(), iLenTemp_)) {
iPos_ += iLenTemp_;
}
}
}
@@ -421,8 +421,8 @@ namespace OHOS::xml {
if (max_ != position_) {
max_ -= position_;
for (size_t i = 0; i < max_; ++i) {
strXml_[i] = strXml_[position_ + i];
for (size_t j = 0; j < max_; ++j) {
strXml_[j] = strXml_[position_ + j];
}
} else {
max_ = 0;
@@ -562,6 +562,8 @@ namespace OHOS::xml {
return TagEnum::ELEMENTDECL;
case 'N':
return TagEnum::ENTITYDECL;
default:
break;
}
xmlPullParserError_ = "Unexpected <!";
break;
@@ -569,6 +571,8 @@ namespace OHOS::xml {
return TagEnum::ATTLISTDECL;
case 'N':
return TagEnum::NOTATIONDECL;
default:
break;
}
return TagEnum::ERROR1;
}
@@ -984,13 +988,13 @@ namespace OHOS::xml {
if (any) {
ParseNspFunction();
}
size_t cut = name_.find(':');
if (cut == 0) {
size_t cut_ = name_.find(':');
if (cut_ == 0) {
xmlPullParserError_ = "illegal tag name: " + name_;
}
if (cut != std::string::npos) {
prefix_ = name_.substr(0, cut);
name_ = name_.substr(cut + 1);
if (cut_ != std::string::npos) {
prefix_ = name_.substr(0, cut_);
name_ = name_.substr(cut_ + 1);
}
namespace_ = GetNamespace(prefix_);
if (namespace_ == "") {
@@ -1456,11 +1460,11 @@ namespace OHOS::xml {
ParseComment(false);
break;
case TagEnum::PARAMETER_ENTITY_REF:
break;
xmlPullParserError_ = "Parameter entity references are not supported ";
default:
break;
default:
xmlPullParserError_ = "Unexpected token";
break;
}
}
}
@@ -1572,15 +1576,6 @@ namespace OHOS::xml {
ParseOneTag();
}
return type;
if (type == TagEnum::WHITESPACE) {
text_ = "";
}
TagEnum typeTemp = ParseTagType(false);
if (text_ != "" && !(text_ == "") && typeTemp < TagEnum::TEXT) {
type = TagEnum::TEXT;
return type;
}
type = typeTemp;
}
}
+17 -16
View File
@@ -42,18 +42,19 @@ class XmlSerializer {
xmlSerializerClass : NativeXMLSerializer;
constructor() {
if(typeof arguments[0] !== 'object') {
throw new Error("input type err");
throw new Error('input type err');
}
if (arguments.length === 1) {
this.xmlSerializerClass = new XML.XmlSerializer(arguments[0], 'utf-8');
const inputType :string = 'utf-8';
this.xmlSerializerClass = new XML.XmlSerializer(arguments[0], inputType);
} else if (arguments.length === 2 && (typeof arguments[1] === 'string' && arguments[1].length !== 0)) {
var strTemp = arguments[1];
if (strTemp.toLowerCase() !== 'utf-8') {
throw new Error("Just support utf-8");
throw new Error('Just support utf-8');
}
this.xmlSerializerClass = new XML.XmlSerializer(arguments[0], arguments[1]);
} else {
throw new Error("input type err");
throw new Error('input type err');
}
let errStr = this.xmlSerializerClass.XmlSerializerError();
if (errStr.length !== 0) {
@@ -62,7 +63,7 @@ class XmlSerializer {
}
setAttributes(name : string, value : string) {
if (typeof name !== 'string' || name.length === 0 || typeof value !== 'string' || name.length === 0 ) {
throw new Error("name or value type err");
throw new Error('name or value type err');
}
this.xmlSerializerClass.setAttributes(name, value);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -72,7 +73,7 @@ class XmlSerializer {
}
addEmptyElement(name : string) {
if (typeof name !== 'string' || name.length === 0) {
throw new Error("name type err");
throw new Error('name type err');
}
this.xmlSerializerClass.addEmptyElement(name);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -89,7 +90,7 @@ class XmlSerializer {
}
startElement(name : string) {
if (typeof name !== 'string' || name.length === 0) {
throw new Error("name type err");
throw new Error('name type err');
}
this.xmlSerializerClass.startElement(name);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -106,7 +107,7 @@ class XmlSerializer {
}
setNamespace(prefix : string, ns : string) {
if (typeof prefix !== 'string' || prefix.length === 0 || typeof ns !== 'string' || ns.length === 0 ) {
throw new Error("prefix or namespace type err");
throw new Error('prefix or namespace type err');
}
this.xmlSerializerClass.setNamespace(prefix, ns);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -116,7 +117,7 @@ class XmlSerializer {
}
setComment(text : string) {
if (typeof text !== 'string' || text.length === 0) {
throw new Error("text type err");
throw new Error('text type err');
}
this.xmlSerializerClass.setComment(text);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -126,7 +127,7 @@ class XmlSerializer {
}
setCDATA(text : string) {
if (typeof text !== 'string' || text.length === 0) {
throw new Error("text type err");
throw new Error('text type err');
}
this.xmlSerializerClass.setCDATA(text);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -136,7 +137,7 @@ class XmlSerializer {
}
setText(text : string) {
if (typeof text !== 'string' || text.length === 0) {
throw new Error("text type err");
throw new Error('text type err');
}
this.xmlSerializerClass.setText(text);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -146,7 +147,7 @@ class XmlSerializer {
}
setDocType(text : string) {
if (typeof text !== 'string' || text.length === 0) {
throw new Error("text type err");
throw new Error('text type err');
}
this.xmlSerializerClass.setDocType(text);
let errStr = this.xmlSerializerClass.XmlSerializerError();
@@ -160,7 +161,7 @@ class XmlPullParser {
xmlPullParserClass : NativeXmlPullParser;
constructor() {
if(typeof arguments[0] !== 'object') {
throw new Error("input type err");
throw new Error('input type err');
}
if (arguments.length === 1) {
let str = 'utf-8';
@@ -168,11 +169,11 @@ class XmlPullParser {
} else if (arguments.length === 2 && (typeof arguments[1] === 'string' && arguments[1].length !== 0)) {
var strTemp = arguments[1];
if (strTemp.toLowerCase() !== 'utf-8') {
throw new Error("Just support utf-8");
throw new Error('Just support utf-8');
}
this.xmlPullParserClass = new XML.XmlPullParser(arguments[0], arguments[1]);
} else {
throw new Error("input type err");
throw new Error('input type err');
}
let errStr = this.xmlPullParserClass.XmlPullParserError();
if (errStr.length !== 0) {
@@ -181,7 +182,7 @@ class XmlPullParser {
}
parse(options : object) {
if(typeof options !== 'object') {
throw new Error("options type err");
throw new Error('options type err');
}
this.xmlPullParserClass.parse(options);
let errStr = this.xmlPullParserClass.XmlPullParserError();