Skip to content

fix #1705: проверка приемника данных; возврат строки из Закрыть#1706

Open
Mr-Rm wants to merge 2 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1705
Open

fix #1705: проверка приемника данных; возврат строки из Закрыть#1706
Mr-Rm wants to merge 2 commits into
EvilBeaver:developfrom
Mr-Rm:v2/fix-1705

Conversation

@Mr-Rm

@Mr-Rm Mr-Rm commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Bug Fixes
    • Added an “open check” guard to XML writing operations, preventing errors when the writer is closed or uninitialized.
    • Improved Закрыть() behavior to be null-safe and consistently return an empty string when there’s no output (string vs. file modes handled correctly).
    • Updated unsupported XML node type handling to throw a dedicated copying-not-supported exception.
  • Tests
    • Added acceptance tests to verify Закрыть() on a newly created writer returns an empty string and the expected string return type.
    • Added acceptance tests to confirm the same behavior when Закрыть() is called after opening a file.

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bb62c432-4e28-49ee-b460-7c567d1f4f88

📥 Commits

Reviewing files that changed from the base of the PR and between 48f75cd and 2e6af73.

📒 Files selected for processing (1)
  • src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs

📝 Walkthrough

Walkthrough

XmlWriterImpl now checks that the writer is open before writing, returns an empty string from Close() when already closed, and keeps Dispose() null-safe. The XML write acceptance tests add coverage for Close() on a fresh writer and after file output.

XmlWriterImpl null-safety and Close() refactor

Layer / File(s) Summary
CheckIfOpen helper and exception constructors
src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
XmlWriterImpl initializes settings and namespace stack directly, adds CheckIfOpen(), and updates NotOpenException() and CopyingNotSupportedException() to construct RuntimeException from two strings.
CheckIfOpen guards on write methods
src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
WriteAttribute, context write methods, start-element and XML text methods, WriteCurrent, WriteDocumentType, and LookupPrefix now call CheckIfOpen() at entry; WriteCurrent unsupported-node handling now throws CopyingNotSupportedException(nodeType).
Close() and Dispose() null-safety
src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
Close() returns String.Empty when _writer is null, otherwise flushes, closes, disposes, and returns buffered string output in string mode; Dispose() now uses _writer?.Close().
Acceptance tests for Close()
tests/xmlwrite.os
Two exported tests are registered and implemented to assert that Close() returns an empty String on a new writer and after ОткрытьФайл.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • EvilBeaver

🐇 I hopped through the writer’s gate,
Checked if open, never late.
Close returns a tiny empty string,
No null surprises in the spring.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: adding open-state checks and making Закрыть return a string.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@maximkin7

maximkin7 commented Jun 29, 2026 via email

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs (2)

313-326: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

WriteDocumentType has the same omitted-argument bug.

The branch conditions here also assume omitted optional strings are null. In script calls they arrive as "", so a shorter call can take the wrong WriteDocType(...) branch and pass the DTD parts in the wrong slots. This needs the same fix as WriteAttribute: stop using optional concrete string parameters when omission changes behavior.

Based on learnings, omitted concrete string parameters from scripts arrive as "", not null, so these null checks do not reliably encode arity.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs` around lines 313 - 326,
WriteDocumentType in XmlWriterImpl has the same omitted-argument handling bug as
WriteAttribute, because it branches on nullable string parameters even though
omitted script arguments arrive as empty strings. Update the method
signature/dispatch so it determines the intended arity without relying on null
checks, and make sure the WriteDocType call maps the DTD parts into the correct
slots for 1-, 2-, 3-, and 4-argument calls.

Source: Learnings


85-95: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

WriteAttribute still misdetects omitted script arguments.

value == null only works for direct C# callers. From OneScript, omitting the third string argument passes "", so a two-argument script call will go through the namespace overload and write the wrong attribute. Use a non-string sentinel (IValue/BslValue) or split the overloads so empty string stays a valid value.

Based on learnings, omitted concrete string parameters from scripts arrive as "", not null, so null-based overload detection is unsafe here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs` around lines 85 - 95, The
WriteAttribute method in XmlWriterImpl still relies on value == null to detect
whether the third argument was omitted, but OneScript passes omitted string
arguments as empty strings. Update WriteAttribute so it distinguishes omission
from an explicit empty string using a non-string sentinel (such as
IValue/BslValue) or by splitting the overloads, and keep the namespace overload
path only for the truly omitted case while preserving empty string as a valid
attribute value.

Source: Learnings

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs`:
- Around line 54-59: `CheckIfOpen()` is not being used consistently across the
public write surface, and `WriteNamespaceMapping()` can still hit `_writer` when
the writer is closed. Update `XmlWriterImpl.WriteNamespaceMapping()` to guard
with `CheckIfOpen()` the same way other write entry points do, and make sure it
raises `NotOpenException()` before any `_writer` access so the public API fails
consistently.

---

Outside diff comments:
In `@src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs`:
- Around line 313-326: WriteDocumentType in XmlWriterImpl has the same
omitted-argument handling bug as WriteAttribute, because it branches on nullable
string parameters even though omitted script arguments arrive as empty strings.
Update the method signature/dispatch so it determines the intended arity without
relying on null checks, and make sure the WriteDocType call maps the DTD parts
into the correct slots for 1-, 2-, 3-, and 4-argument calls.
- Around line 85-95: The WriteAttribute method in XmlWriterImpl still relies on
value == null to detect whether the third argument was omitted, but OneScript
passes omitted string arguments as empty strings. Update WriteAttribute so it
distinguishes omission from an explicit empty string using a non-string sentinel
(such as IValue/BslValue) or by splitting the overloads, and keep the namespace
overload path only for the truly omitted case while preserving empty string as a
valid attribute value.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4340bfac-cdbf-4471-84d4-d0aa45759bac

📥 Commits

Reviewing files that changed from the base of the PR and between 0cd65f0 and 48f75cd.

📒 Files selected for processing (2)
  • src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
  • tests/xmlwrite.os

Comment thread src/OneScript.StandardLibrary/Xml/XmlWriterImpl.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants