Skip to content

Commit

Permalink
Issue #155: Fixed gsub() on array elements
Browse files Browse the repository at this point in the history
  • Loading branch information
bertysentry committed Aug 29, 2024
1 parent bbaa630 commit cccd992
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/sentrysoftware/jawk/backend/AVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,8 @@ public void interpret(AwkTuples tuples)
// ARRAY reference offset/is_global
long offset = position.intArg(0);
boolean is_global = position.boolArg(1);
String newString = execSubOrGSub(position, 2);
Object arr_idx = pop();
String newString = execSubOrGSub(position, 2);
// assign it to "offset/arr_idx/global"
assignArray(offset, arr_idx, newString, is_global);
pop();
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/sentrysoftware/jawk/AwkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,4 +398,13 @@ public void testPrintComparison() throws Exception {
);
}

@Test
public void testGsubArray() throws Exception {
assertEquals(
"gsub on an array element must change the value of the element",
"abcd\n",
runAwk("BEGIN { a[1] = \"ab:cd\"; gsub(/:/, \"\", a[1]); print a[1]; }", null)
);
}

}

0 comments on commit cccd992

Please # to comment.