Bug Squash
Problem Statement
1) mako
Source files: https://drive.google.com/file/d/1o3-NV1TYjvTPiDQyZU6pTUM1nUfy9UHP/view?usp=sharing
You will be asked to fix some failing tests in a codebase.
Fix a unit test called test_lookup.py
Other bugs
2) requests
Source files: https://drive.google.com/file/d/1t25qFe5ga1hbP2lHj_yn75jFozexnaLg/view?usp=sharing
Scenario: When making an HTTP request where the request body is a ByteIO object, the request works fine the first time. However, if a redirect happens, the second request (following the redirect) causes a timeout.
Key Behavior: This happens because ByteIO is a stream-like object that can only be read once unless the stream's position is reset. After the first read, the ByteIO object is "exhausted," meaning subsequent reads return an empty bytes object (b'').
Hint: the timeout issue in requests occurred because after redirection and making a request again, the BytesIO pointer was not reset. You can check the BytesIO API, and use seek() and tell() to fix it.
3) jackson-core
Source files: https://drive.google.com/file/d/1y6w9g0whyFYoiKFNtbs1rDE6eSFT5rbv/view?usp=sharing
It's similar to fixing an issue on GitHub. The problem is about debugging an issue with Jackson-core library's deserialization of Infinity values.
The JSON string is:
final String JSON = "[ -INF, +INF, +Infinity, Infinity, -Infinity ]";
The following test will fail:
assertToken(JsonToken.VALUE_NUMBER_FLOAT, jp.nextToken());
d = jp.getDoubleValue();
assertEquals("Infinity", jp.getText());
assertTrue(Double.isInfinite(d));
assertTrue(d == Double.POSITIVE_INFINITY);
4) moshi (java/kotlin)
Reference: https://www.1point3acres.com/bbs/thread-1102663-1-1.html, https://www.1point3acres.com/bbs/thread-1093703-1-1.html
Source files: moshi
Bug: endObject and endArray did not call nextElement
Note:
The initial state of the repo might only have one failing test when you run the tests, which don’t match the three failing tests others mentioned. The reason is that the repo already had debug code added, but it also included a newly added test case, and it was this new test case that failed.
To reproduce the scenario where three test cases fail, you can check the edit history in your IDE (e.g., the green highlights in IntelliJ IDEA). Remove the newly added test case, and delete the debug code from endObject and endArray. After doing this, you should be able to replicate the three failing test cases.
5) html/template (golang)
Reference: https://www.1point3acres.com/bbs/thread-1088278-1-1.html
The repo content is some logic directly copied from the html/template package (https://pkg.go.dev/html/template). The repo also has some unit tests, which initially failed and needed to be fixed. I hadn't used html/template before, so I spent quite some time understanding how this package is used. The bug is roughly as follows:
When parsing a template, if it's {{nil}}, there's no problem, but if it's {{nil.foo}}, it will throw an error. When processing chained nodes like {{nil.foo}}, a nil node check needs to be added. If the first child node in the chained node is a nil node type, it should return directly.
Since I had never used this package before, I was confused about what the code was doing. After debugging for a while, I confirmed the problem but wasn't sure where to make the change. I asked the interviewer, and he guided me step by step, finally saying that the change should be made in the evalChainNode method. It's the check between the Fix start and end comments below.
func (s *state) evalChainNode(dot reflect.Value, chain *parse.ChainNode, args []parse.Node, final reflect.Value) reflect.Value {
s.at(chain)
// Fix start
if chain.Node.Type() == parse.NodeNil {
return reflect.Value{} // Return zero value for nil
}
// Fix end
// (pipe).Field1.Field2 has pipe as .Node, fields as .Field. Eval the pipeline, then the fields.
pipe := s.evalArg(dot, nil, chain.Node)
if len(chain.Field) == 0 {
s.errorf("internal error: no fields in evalChainNode")
}
return s.evalFieldChain(dot, pipe, chain, chain.Field, args, final)
}
6) yaml-cpp
Fixing actual bugs that have appeared in the repo: https://github.com/jbeder/yaml-cpp
One of the bugs was an issue with parsing tags. Specifically, the YAML tag is allowed to contain parentheses, but the version they provided has a bug. It mistakenly assumes the tag ends whenever it encounters a parenthesis."
7) toml (golang)
Fix some bugs in the toml repo.
Basically just need to follow what this PR did: https://github.com/BurntSushi/toml/pull/281/files#diff-e66fb2b3e2ed56aa1614ff2ff129bfd9c48111d3ec9e222e196ec18022750eb4