TWSD-1350 Not displaying the list of interfaces when the interface name is modified with special characters especially like this format port1(data_

Review Request #1257 — Created Dec. 23, 2025 and updated

lucille
APV10
rel_apv_10_7
TWSD-1350
austin, shuinvy, weikai

The WebUI list page fails to display interface names that contain special characters

Root Cause

When SystemInterface or BondInterface interface names contain regular expression special characters (such as parentheses (, periods ., etc.), it causes 500 errors during DelayedQuery processing.

Specific Cause:
1. In the _get_management method, interface names are directly inserted into regular expressions
2. When interface name is "port1(Data_", the generated regular expression becomes:
interface management "port1(Data_" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)
3. The parenthesis ( is a special character for grouping syntax in regular expressions, causing regex syntax errors
4. The error occurs during the DelayedQuery processing phase of GET requests, not during UPDATE operations

Solution

Use the re.escape() function to escape interface names for regular expressions in both _get_management methods.

Modified Locations:

1. SystemInterface._get_management (Line 537)

@QueryingFields(['manage_port','gateway_ipv4', 'gateway_ipv6'])
def _get_management(self, pk_dict):
    self.cli.set_enable()
    result = self.cli.cmd('show management',
                          RegexParser('interface management "%s" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)' % re.escape(pk_dict['name']), MATCHALL)
                          )
    # ... rest of the code remains unchanged

2. BondInterface._get_management (Line 707)

@QueryingFields(['manage_port','gateway_ipv4', 'gateway_ipv6'])
def _get_management(self, pk_dict):
    self.cli.set_enable()
    result = self.cli.cmd('show management',
                          RegexParser('interface management "%s" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)' % re.escape(pk_dict['name']), MATCHALL)
                          )
    # ... rest of the code remains unchanged

Modification Effect:
- Original: "port1(Data_" → Regular expression: "port1(Data_"
- After escaping: "port1(Data_" → Regular expression: "port1\\(Data_"

Verification

Test Steps:
1. Create interface names containing special characters, such as: "port1(Data_"
2. Access SystemInterface or BondInterface list pages via Web UI or REST API
3. Confirm that 500 errors no longer occur
4. Verify that interface names with special characters properly display management interface related fields

Expected Results:
- ✅ No more 500 Internal Server Error
- ✅ Interface names with special characters are handled properly
- ✅ manage_port, gateway_ipv4, gateway_ipv6 fields display correctly
- ✅ Interface names without special characters remain unaffected

Test Coverage:
- Interface names containing: ()[]{}.*+?^$| and other regex special characters
- Both SystemInterface and BondInterface classes
- GET request DelayedQuery processing flow

austin
  1. Ship It!
  2. 
      
lucille
shuinvy
  1. Ship It!
  2. 
      
lucille
Review request changed

Testing Done:

~  

Root Cause:

  ~

Root Cause

   
~  

The WebUI list page fails to display interface names that contain special characters (especially parentheses ( and underscore _, for example: "port1(data_").

  ~

When SystemInterface or BondInterface interface names contain regular expression special characters (such as parentheses (, periods ., etc.), it causes 500 errors during DelayedQuery processing.

-   This issue occurs during the character encoding and conversion process in the data handling logic:

   
~  
  1. Inconsistent character encoding handling:
    Different Unicode conversion functions are used in the field-processing loops:
  ~

Specific Cause:

  + 1. In the _get_management method, interface names are directly inserted into regular expressions
  + 2. When interface name is "port1(Data_", the generated regular expression becomes:
  + interface management "port1(Data_" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)
  + 3. The parenthesis ( is a special character for grouping syntax in regular expressions, causing regex syntax errors
  + 4. The error occurs during the DelayedQuery processing phase of GET requests, not during UPDATE operations

   
~  
  • stats_table uses smart_unicode(x)
  ~

Solution

-  
  • config_table uses unicode(x)

-  
  • Differences in conversion behavior:
    smart_unicode() and unicode() handle special characters differently, which can result in inconsistent output when interface names contain special characters.

-  
  • Insufficient error handling:
    When character conversion fails, the except block simply assigns an empty string, without meaningful error handling or a fallback mechanism.

   
~  
  ~

Use the re.escape() function to escape interface names for regular expressions in both _get_management methods.

   
~  

Solution:

  ~

Modified Locations:

   
~  

Unify the character handling approach to ensure consistent encoding conversion in all cases:

  ~

1. SystemInterface._get_management (Line 537)

   
~  
  1. Standardize the character conversion function:
  ~
@QueryingFields(['manage_port','gateway_ipv4', 'gateway_ipv6'])
  +
def _get_management(self, pk_dict):
  +
    self.cli.set_enable()
  +
    result = self.cli.cmd('show management',
  +
                          RegexParser('interface management "%s" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)' % re.escape(pk_dict['name']), MATCHALL)
  +
                          )
  +
    # ... rest of the code remains unchanged
  +
   
~  

```python

  ~

-   # In stats_table method – keep using smart_unicode
-   for fn in field_list:
-   try:
-   ret_val = get_complex_field(each, fn, ins_manager, 'display_for_list')
-   if ret_val:
-   value_list = [smart_unicode(x) for x in ret_val.values()]
-   value = ', '.join(value_list)
-   sub_ret[fn] = value
-   except:
-   sub_ret[fn] = ''

   
~  

# In config_table method – switch to smart_unicode for consistency

  ~

2. BondInterface._get_management (Line 707)

-   for fn in field_list:
-   try:
-   ret_val = get_complex_field(each, fn, ins_manager, 'display_for_list')
-   if ret_val:
-   value_list = [smart_unicode(x) for x in ret_val.values()] # changed to smart_unicode
-   value = ', '.join(value_list)
-   sub_ret[fn] = value
-   except:
-   sub_ret[fn] = ''
-   ```

   
~  
  1. Improve error handling:
    Add more specific exception handling to ensure a proper fallback when special character conversion fails.
  ~
@QueryingFields(['manage_port','gateway_ipv4', 'gateway_ipv6'])
  +
def _get_management(self, pk_dict):
  +
    self.cli.set_enable()
  +
    result = self.cli.cmd('show management',
  +
                          RegexParser('interface management "%s" (?P<gateway_ip_str>[0-9|a-f|A-F|:|\.]+)' % re.escape(pk_dict['name']), MATCHALL)
  +
                          )
  +
    # ... rest of the code remains unchanged
  +
   
~  
  ~

   
~  

Verify:

  ~

Modification Effect:

  + - Original: "port1(Data_" → Regular expression: "port1(Data_"
  + - After escaping: "port1(Data_" → Regular expression: "port1\\(Data_"

   
~  

After applying the fix, verify the following:

  ~

Verification

   
~  
  1. Consistency test:
    Ensure both stats_table and config_table produce consistent results for interface names with special characters.

~  
  1. Character integrity check:
    Validate that interface names containing special characters (parentheses, underscores, and other Unicode characters) are displayed correctly.

~  
  1. Regression testing:
    Confirm that interface names with standard characters are not affected.

~  
  1. Error handling validation:
    Verify that the system gracefully degrades when character conversion fails, without causing crashes or display issues.

  ~

Test Steps:

  ~ 1. Create interface names containing special characters, such as: "port1(Data_"
  ~ 2. Access SystemInterface or BondInterface list pages via Web UI or REST API
  ~ 3. Confirm that 500 errors no longer occur
  + 4. Verify that interface names with special characters properly display management interface related fields

   
~  

Key Change:

~   Standardize the use of smart_unicode() for character conversion to ensure consistent and correct handling of special characters across the system.

  ~

Expected Results:

  ~ - ✅ No more 500 Internal Server Error
  + - ✅ Interface names with special characters are handled properly
  + - ✅ manage_port, gateway_ipv4, gateway_ipv6 fields display correctly
  + - ✅ Interface names without special characters remain unaffected

  +
  +

Test Coverage:

  + - Interface names containing: ()[]{}.*+?^$| and other regex special characters
  + - Both SystemInterface and BondInterface classes
  + - GET request DelayedQuery processing flow

austin
  1. Ship It!
  2. 
      
Loading...