Code verification method, device, storage medium and processor
By filtering and verifying the code types, and using the configuration type scanning method, redundant code and logic problems in page development are solved, development efficiency and code readability are improved, and vulnerabilities are reduced.
Patent Information
- Application Number
- CN202111649986.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2041-12-29
AI Technical Summary
In page development, there are redundant code, incomplete code logic verification, irregular writing, and low development efficiency, frequent compatibility problems, and lack of effective code verification methods.
By obtaining task identification information, scanning the code under the storage path, filtering and verification according to the target code type, calling the configuration type scanning method for verification, including the number of subcode references analysis, clearing, merging and historical content processing, and generating a verification report.
It improves development efficiency, reduces code vulnerabilities, improves code readability, and solves the problems of low development efficiency and poor code readability.
Smart Images

Figure CN114296796B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of code development, and in particular to a code verification method, device, storage medium and processor. Background Art
[0002] In page development, it is often necessary to write JS, HTML, JSP, VUE and other types of codes for page development, and the code needs to be constantly updated and upgraded during the development process. After the update and upgrade, the following problems often exist: ① There is redundant code, which reduces the readability of the front-end code; ② There is incomplete verification of the code logic, which leads to frequent problems; ③ The page writing is not standardized, resulting in frequent incompatibility and compatibility problems; ④ JS, HTML, VUE, etc. are not standardized during development, resulting in reduced development efficiency. Therefore, there is an urgent need for a method to effectively verify the code.
[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0004] The embodiments of the present application provide a code verification method, device, storage medium and processor to at least solve the technical problems of low development efficiency, low code readability and many code vulnerabilities caused by the lack of effective code verification methods in related technologies.
[0005] According to one aspect of an embodiment of the present application, a code verification method is provided, including: obtaining identification information corresponding to a task; scanning the code corresponding to the identification information under each storage path in a storage area, and determining the code as a first code corresponding to the task; obtaining a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified; filtering the first code according to the target code type to obtain a second code; calling a scanning method corresponding to the first file configuration type to verify the second code, and obtaining a verification report, wherein the scanning method at least includes: a writing rule for the target code type.
[0006] Optionally, the scanning method corresponding to the first file configuration type is called to verify the second code, including: determining each sub-code referenced in the second code; marking each sub-code and determining the number of references of each sub-code; determining a first target sub-code in each sub-code whose number of references is less than a threshold, and calling the scanning method to scan and verify other sub-codes in the second code except the first target sub-code.
[0007] Optionally, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: determining a second target subcode with a reference number of zero in each subcode; calling a code clearing application interface to clear the second target subcode to obtain a cleared second code; calling the scanning method corresponding to the first file configuration type to verify the cleared second code.
[0008] Optionally, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: determining a third target subcode in each subcode whose number of references is greater than a threshold; determining a fourth target subcode with the same content in the third target subcode; merging the fourth target subcode in the second code to obtain a merged second code; and calling the scanning method corresponding to the first file configuration type to verify the merged second code.
[0009] Optionally, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: obtaining the modified content in the second code within the historical period; determining the original code in the second code that has not been modified within the historical period based on the modified content; and calling the scanning method to scan and verify the code other than the original code in the second code.
[0010] Optionally, when it is determined that the target code type does not exist in the first code, prompt information is generated, wherein the prompt information is used to prompt the target object whether to adjust the configuration type of the first file to be scanned.
[0011] Optionally, after generating the prompt information, the method also includes: receiving a modification instruction of the target object, modifying the first file configuration type based on the modification content indicated by the modification instruction to obtain a second file configuration type; calling a scanning method corresponding to the second file configuration type to verify the second code to obtain a verification report.
[0012] According to another aspect of an embodiment of the present application, a code verification device is also provided, including: a first acquisition module, used to obtain identification information corresponding to a task; a scanning module, used to scan the code corresponding to the identification information under each storage path in the storage area, and determine the code as the first code corresponding to the task; a second acquisition module, used to obtain the first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate the target code type to be verified; a screening module, used to filter the first code according to the target code type to obtain a second code; a verification module, used to call the scanning method corresponding to the first file configuration type to verify the second code, and obtain a verification report, wherein the scanning method at least includes: writing rules for the target code type.
[0013] According to another aspect of an embodiment of the present application, a non-volatile storage medium is further provided, the non-volatile storage medium including a stored program, wherein when the program is running, a device where the non-volatile storage medium is located is controlled to execute any one of the code verification methods.
[0014] According to another aspect of an embodiment of the present application, a processor is further provided, and the processor is used to run a program, wherein any code verification method is executed when the program is running.
[0015] In an embodiment of the present application, the code types are divided, and the scanning methods of each code type are called to verify the code, by obtaining the identification information corresponding to the task; scanning the code corresponding to the identification information under each storage path in the storage area, and determining the code as the first code corresponding to the task; obtaining the first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate the target code type to be verified; the first code is screened according to the target code type to obtain the second code; calling the scanning method corresponding to the first file configuration type to verify the second code, and obtaining a verification report, wherein the scanning method at least includes: writing rules for the target code type, thereby achieving the purpose of verifying the code, thereby realizing the technical effect of improving development efficiency, saving development time, improving code readability, and reducing code vulnerabilities, thereby solving the technical problems of low development efficiency, low code readability, and more code vulnerabilities caused by the lack of effective methods for verifying the code in related technologies. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0017] Figure 1 is a flowchart of an optional code verification method according to an embodiment of the present application;
[0018] Figure 2 is a flowchart of another optional code verification according to an embodiment of the present application;
[0019] Figure 3 It is a schematic diagram of the structure of an optional code verification device according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] According to an embodiment of the present application, a method embodiment of code verification is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0023] Figure 1 is a code verification method according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0024] Step S102, obtaining identification information corresponding to the task;
[0025] Step S104, scanning the code corresponding to the identification information under each storage path in the storage area, and determining the code as the first code corresponding to the task;
[0026] Step S106, obtaining a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified;
[0027] Step S108, filtering the first code according to the target code type to obtain a second code;
[0028] Step S110, calling a scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: a writing rule of the target code type.
[0029] In the code verification method, identification information corresponding to the task is obtained; the code corresponding to the identification information under each storage path in the storage area is scanned, and the code is determined to be the first code corresponding to the task; the first file configuration type to be scanned is obtained, wherein the first file configuration type is at least used to indicate the target code type to be verified; the first code is screened according to the target code type to obtain the second code; the scanning method corresponding to the first file configuration type is called to verify the second code to obtain a verification report, wherein the scanning method at least includes: writing rules for the target code type, thereby achieving the purpose of verifying the code, thereby realizing the technical effects of improving development efficiency, saving development time, improving code readability, and reducing code vulnerabilities, thereby solving the technical problems of low development efficiency, low code readability, and more code vulnerabilities caused by the lack of effective code verification methods in related technologies.
[0030] It is understandable that by screening and verifying the codes based on multiple file configuration types, the technical effect of batch one-stop processing of files without multiple scans can be achieved. For example, the second codes of the two types of JS and HTML in the first code are screened out at the same time, and the scanning methods corresponding to the two types are called to scan and verify the second codes.
[0031] In some optional embodiments of the present application, calling the scanning method corresponding to the first file configuration type to verify the second code can be achieved in the following manner. Specifically, each sub-code referenced in the second code is determined; each sub-code is marked to determine the number of references of each sub-code; a first target sub-code whose number of references is less than a threshold value in each sub-code is determined, and the scanning method is called to scan and verify other sub-codes in the second code except the first target sub-code.
[0032] In some other optional embodiments of the present application, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: determining a second target subcode with zero reference times in each subcode; calling a code clearing application interface to clear the second target subcode to obtain a cleared second code; calling the scanning method corresponding to the first file configuration type to verify the cleared second code.
[0033] In some embodiments of the present application, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: determining a third target subcode in each subcode whose number of references is greater than a threshold; determining a fourth target subcode with the same content in the third target subcode; merging the fourth target subcode in the second code to obtain a merged second code; and calling the scanning method corresponding to the first file configuration type to verify the merged second code.
[0034] In some other optional embodiments of the present application, calling the scanning method corresponding to the first file configuration type to verify the second code also includes: obtaining the modified content in the second code within the historical period; determining the original code in the second code that has not been modified within the historical period based on the modified content; and calling the scanning method to scan and verify the code other than the original code in the second code.
[0035] Optionally, when it is determined that there is no code of the target code type in the first code, prompt information is generated. It should be noted that the prompt information is used to prompt the target object whether to adjust the configuration type of the first file to be scanned.
[0036] In some embodiments of the present application, after generating the prompt information, a modification instruction of the target object can also be received, and the first file configuration type can be modified based on the modification content indicated by the modification instruction to obtain a second file configuration type; the scanning method corresponding to the second file configuration type is called to verify the second code to obtain a verification report.
[0037] Figure 2 This is an optional code verification flow chart for this application, such as Figure 2 As shown, the process includes: the developer initiates a scan to identify and extract the code of each storage path of the storage area, determine whether the configuration is specified (that is, determine whether the first file configuration type is specified, and the first file configuration can at least indicate the target code type to be verified), then obtain the configuration information, and then scan the file to determine whether the scanned content matches the configuration (that is, the scanned content is filtered according to the target code type), and use the scanned content that matches the target code type as the content to be verified, and then perform logic, rule and other verifications, and finally generate a verification report; if it does not match, the user can be prompted to modify the previous configuration information.
[0038] It should be noted that the verification process of the above logic, rules, etc. can be carried out in the following way: through the front-end parser, the specified front-end code is parsed to verify the text, references, names, etc. Prompts are given by scanning the number of references and the file operation time. Files with fewer references and no traces of modification for a long time are prompted. Scanning and verification are not required for files with fewer references and no modification in a predetermined historical period (i.e., determining each subcode referenced in the second code, marking each subcode, determining the number of references of each subcode, determining the first target subcode in each subcode with a number of references less than a threshold, calling a scanning method to scan and verify other subcodes in the second code except the first target subcode, and obtaining the modified content in the second code in the historical period, determining the original code in the second code that has not been modified in the historical period according to the modified content, and calling a scanning method to scan and verify the code in the second code except the original code); in addition, the code can also be logically verified by a parser. The higher the reference frequency, the more verification times. Multiple common verification codes can be marked to extract common methods, i.e., determining the third target subcode in each subcode with a number of references greater than a threshold, determining the fourth target subcode with the same content in the third target subcode, merging the fourth target subcode in the second code to obtain a merged second code; calling the scanning method corresponding to the first file configuration type to verify the merged second code.
[0039] It is easy to notice that the above code verification method can improve the efficiency of front-end development, reduce the occurrence of errors, reduce code redundancy, improve code readability, and facilitate later maintenance and development; in addition, the code type to be verified can be flexibly configured to improve the convenience of use and facilitate developers to use, and this method can be flexibly and quickly imported into the development project by calling, which reduces the difficulty of use. It can be understood that the code can be filtered and verified based on multiple file configuration types to achieve a technical effect of batch one-stop processing of files without multiple scans.
[0040] Figure 3 is a code verification device according to an embodiment of the present application, such as Figure 3 As shown, the device comprises:
[0041] A first acquisition module 40 is used to acquire identification information corresponding to the task;
[0042] A scanning module 42, configured to scan a code corresponding to the identification information under each storage path in the storage area, and determine the code as a first code corresponding to the task;
[0043] A second acquisition module 44 is used to acquire a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified;
[0044] A screening module 46, configured to screen the first code according to the target code type to obtain a second code;
[0045] The verification module 48 is used to call the scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: writing rules of the target code type.
[0046] In the code verification device, a first acquisition module 40 is used to obtain identification information corresponding to a task; a scanning module 42 is used to scan the code corresponding to the identification information under each storage path in the storage area, and determine the code as the first code corresponding to the task; a second acquisition module 44 is used to obtain a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified; a screening module 46 is used to screen the first code according to the target code type to obtain a second code; a verification module 48 is used to call a scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: a writing rule of the target code type, thereby achieving the purpose of verifying the code, thereby realizing the technical effect of improving development efficiency, saving development time, improving code readability, and reducing code vulnerabilities, thereby solving the technical problems of low development efficiency, low code readability, and more code vulnerabilities caused by the lack of an effective method for verifying the code in the related technology.
[0047] According to another aspect of an embodiment of the present application, a non-volatile storage medium is further provided, the non-volatile storage medium including a stored program, wherein when the program is running, a device where the non-volatile storage medium is located is controlled to execute any one of the code verification methods.
[0048] According to another aspect of an embodiment of the present application, a processor is further provided, and the processor is used to run a program, wherein any code verification method is executed when the program is running.
[0049] Specifically, the above storage medium is used to store program instructions for executing the following functions to achieve the following functions:
[0050] Obtain identification information corresponding to the task; scan the code corresponding to the identification information under each storage path in the storage area, and determine the code as the first code corresponding to the task; obtain the first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate the target code type to be verified; filter the first code according to the target code type to obtain the second code; call the scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: writing rules for the target code type.
[0051] Specifically, the processor is used to call the program instructions in the memory to implement the following functions:
[0052] Obtain identification information corresponding to the task; scan the code corresponding to the identification information under each storage path in the storage area, and determine the code as the first code corresponding to the task; obtain the first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate the target code type to be verified; filter the first code according to the target code type to obtain the second code; call the scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: writing rules for the target code type.
[0053] In an embodiment of the present application, the code types are divided, and the scanning methods of each code type are called to verify the code, by obtaining the identification information corresponding to the task; scanning the code corresponding to the identification information under each storage path in the storage area, and determining the code as the first code corresponding to the task; obtaining the first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate the target code type to be verified; the first code is screened according to the target code type to obtain the second code; calling the scanning method corresponding to the first file configuration type to verify the second code, and obtaining a verification report, wherein the scanning method at least includes: writing rules for the target code type, thereby achieving the purpose of verifying the code, thereby realizing the technical effect of improving development efficiency, saving development time, improving code readability, and reducing code vulnerabilities, thereby solving the technical problems of low development efficiency, low code readability, and more code vulnerabilities caused by the lack of effective methods for verifying the code in related technologies.
[0054] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0055] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0056] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0057] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0058] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0059] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.
[0060] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A code verification method, characterized in that: include: Get the identification information corresponding to the task; Scan the code corresponding to the identification information in each storage path in the storage area, and determine the code as the first code corresponding to the task; Obtaining a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified; Screening the first code according to the target code type to obtain a second code; Calling a scanning method corresponding to the first file configuration type to verify the second code to obtain a verification report, wherein the scanning method at least includes: a writing rule for the target code type; Calling a scanning method corresponding to the first file configuration type to verify the second code includes: Determining each subcode referenced in the second code; Marking each subcode and determining the number of citations of each subcode; A first target subcode whose number of citations is less than a threshold value is determined in each of the subcodes, and the scanning method is called to scan and verify the other subcodes in the second code except the first target subcode.
2. The method according to claim 1, characterized in that Calling a scanning method corresponding to the first file configuration type to verify the second code also includes: Determine a second target subcode whose number of citations is zero among the subcodes; Calling a code clearing application program interface to clear the second target subcode, and obtaining the cleared second code; The scanning method corresponding to the first file configuration type is called to verify the cleared second code.
3. The method according to claim 1, characterized in that Calling a scanning method corresponding to the first file configuration type to verify the second code also includes: Determine a third target subcode whose number of citations is greater than a threshold value among the subcodes; Determine a fourth target subcode having the same content as the third target subcode; Merging the fourth target subcode in the second code to obtain a merged second code; The scanning method corresponding to the first file configuration type is called to verify the merged second code.
4. The method according to claim 1, characterized in that: Calling a scanning method corresponding to the first file configuration type to verify the second code also includes: Obtaining the modified content in the second code within a historical period; Determine, according to the modified content, the original code in the second code that has not been modified within the historical period; The scanning method is called to scan and verify the codes in the second code except the original code.
5. The method according to claim 1, characterized in that In the case where it is determined that the target code type does not exist in the first code, prompt information is generated, wherein the prompt information is used to prompt the target object whether to adjust the configuration type of the first file to be scanned.
6. The method according to claim 5, characterized in that After generating the prompt information, the method further includes: receiving a modification instruction of the target object, and modifying the first file configuration type based on the modification content indicated by the modification instruction to obtain a second file configuration type; The scanning method corresponding to the second file configuration type is called to verify the second code to obtain a verification report.
7. A code verification device, characterized in that: include: A first acquisition module is used to acquire identification information corresponding to the task; A scanning module, used for scanning the code corresponding to the identification information in each storage path in the storage area, and determining the code as the first code corresponding to the task; A second acquisition module, used to acquire a first file configuration type to be scanned, wherein the first file configuration type is at least used to indicate a target code type to be verified; A screening module, used for screening the first code according to the target code type to obtain a second code; A verification module, configured to call a scanning method corresponding to the first file configuration type to verify the second code and obtain a verification report, wherein the scanning method at least includes: a writing rule for the target code type; Calling a scanning method corresponding to the first file configuration type to verify the second code includes: Determining each subcode referenced in the second code; Marking each subcode and determining the number of citations of each subcode; A first target subcode whose number of citations is less than a threshold value is determined in each of the subcodes, and the scanning method is called to scan and verify the other subcodes in the second code except the first target subcode.
8. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored program, wherein when the program is running, the device where the non-volatile storage medium is located is controlled to execute the code verification method according to any one of claims 1 to 6.
9. A processor, characterized in that: The processor is used to run a program, wherein the program executes the code verification method described in any one of claims 1 to 6 when running.
Citation Information
Patent Citations
Code scanning method and terminal equipment
CN111597552A
Static code scanning optimization method and device, electronic equipment and storage medium
CN112783749A