Added test cases and applied patch for #22808.