When building websites and handling user input, we often need to ensure the security and correctness of the data.AnQiCMS (AnQiCMS) is an enterprise-level content management system developed based on the Go language, which provides various filters in the template to help us complete these tasks.addslashesA filter is a utility specifically designed for string processing.But when we use it, a natural question may arise in our minds: will this filter change the length of the original string?If so, how much will it increase?

addslashesThe working principle of the filter and the change of string length

The answer is affirmative,addslashesThe filter does indeed change the length of the original string and usually causes it to increase. Specifically, it inserts a backslash before certain predefined characters in the string.\)Perform escaping. Each time such a specific character is encountered, the length of the string increases by 1 character.

Then, which characters will beaddslashesFilter processing? According to the AnQiCMS documentation, it will automatically add a backslash before the following characters:

  • Single quote (')
  • Double quote (")
  • Backslash (\)
  • NUL (NULL character)

This means, if your original string contains these characters,addslashesTherefore, if there are N characters that need to be escaped in your string, they will be "protected" by being preceded by a backslash.addslashesProcessed, the final length of the string will increase by N.

Let's see this change through a few simple examples:

  1. Processing single quotes:
    • Original string:安企'CMS
    • Original length: 7
    • Use filter: `